c# - HttpWebRequest + GetResponseStream encoding -
how can decode http stream response?
i error message:
there error deserializing object of type test.rootobject '�yl�' contains invalid utf8 bytes.
here code:
httpwebrequest request = webrequest.create(urlrequest) httpwebrequest; //request.headers.add(httprequestheader.acceptcharset, "utf-8"); // cannot work! using (httpwebresponse response = request.getresponse() httpwebresponse) { if (response.statuscode != httpstatuscode.ok) { throw new exception(string.format("server error (http {0}: {1}).", response.statuscode, response.statusdescription)); } datacontractjsonserializersettings settings = new datacontractjsonserializersettings(); datacontractjsonserializer jsonserializer = new datacontractjsonserializer(typeof(rootobject)); object objresponse = jsonserializer.readobject(response.getresponsestream()); //// cannot work! //using (stream resstream = response.getresponsestream()) //{ // streamreader reader = new streamreader(resstream, encoding.utf8); // reader.readtoend(); //} //// test
Comments
Post a Comment