Home > Net > C # use post method use URL json data, appear system.net.webexception: remote server returns an erro
C # use post method use URL json data, appear system.net.webexception: remote server returns an erro
Time:09-29
Code to run when there is no problem, let the program has been running in uncertain time errors will occur, sometimes one day there is an error, sometimes this error is a few hours, the couple small white request support ah Public string GetResponseData (string JSONData, string Url) {
The string url="url"; Byte [] bytes=Encoding. UTF8. GetBytes (JSONData); HttpWebRequest request=(HttpWebRequest) WebRequest. Create (url); Request. The Method="POST"; Request. The ContentLength=bytes. The Length; Request. The ContentType="application/json; Charset=utf-8 "; Stream reqstream=request. GetRequestStream (); Reqstream. Write (0 bytes, bytes. The Length).
//declare a HttpWebRequest request //request Timeout=60000; //sets the connection timeout time Request. Headers. Set (" Pragma ", "no - cache"); HttpWebResponse response=(HttpWebResponse) request. The method GetResponse (); Stream streamReceive=response. GetResponseStream (); Encoding Encoding.=Encoding UTF8;