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;

StreamReader StreamReader=new StreamReader (streamReceive, encoding);
String strResult=streamReader. ReadToEnd ();
StreamReceive. The Dispose ();
StreamReader. The Dispose ();
Console. WriteLine (strResult);
WriteMessage (strResult);
Return strResult;

}

CodePudding user response:

Server internal error, check the site log to identify specific reasons

CodePudding user response:

What's wrong?

CodePudding user response:

refer to the third floor is nu month god reply:
what's wrong?
run without errors, long run time will appear to a remote server returns an error: (500) internal server error, sometimes a few hours there is an error, sometimes one day in the wrong

CodePudding user response:

reference 1st floor LvBao_117 response:
server internal error, check the site log to identify the specific reasons for
the weak weak ask site log in where to look, new small white don't understand, thank you for your bosses

CodePudding user response:

Abnormal depends on server, the server interface if there is a best global exception handling, no words make a try on the interface cache catch exceptions, and logging

CodePudding user response:

reference 4 floor qq_39299631 response:
Quote: refer to the third floor is nu month god reply:

What's wrong?
run without error, long run time will appear to a remote server returns an error: (500) internal server error, sometimes a few hours there is an error, and sometimes one day appear the error

500 error, is the program,
, of course, the data can also cause your program 500 mistakes,

CodePudding user response:

references on 7th floor is wrath of god reply:
Quote: refer to 4th floor qq_39299631 response:

Quote: refer to the third floor is nu month god reply:

What's wrong?
run without error, long run time will appear to a remote server returns an error: (500) internal server error, sometimes a few hours there is an error, and sometimes one day appear the error

500 error, is the program,
, of course, the data can also cause your program 500 mistakes,

that how to avoid or prevent errors happen

CodePudding user response:

Well, ok, thank you

CodePudding user response:

refer to the eighth floor qq_39299631 response:
Quote: refer to 7th floor is nu month god reply:

Quote: refer to 4th floor qq_39299631 response:

Quote: refer to the third floor is nu month god reply:

What's wrong?
run without error, long run time will appear to a remote server returns an error: (500) internal server error, sometimes a few hours there is an error, and sometimes one day appear the error

500 error, is the program,
, of course, the data can also cause your program 500 mistakes,

what about how to avoid mistakes or prevents errors

You'll have to find the wrong place, fix the bug

CodePudding user response:

Well, ok, thank you
  •  Tags:  
  • C#
  • Related