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

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -