this is a postman headers, did not change
Request method is post, the Body parts in the x - WWW - form - unlencoded inside (on the form - data also can appear error)
Then this is the class web page request program
public static TupleUrlRequest (string UrlAddress, string RequestMethod, string RequestData=https://bbs.csdn.net/topics/null, string Cookie=null)
{
Try
{
GC. Collect ();
HttpWebRequest request=(HttpWebRequest) WebRequest. Create (UrlAddress);
Request. AllowAutoRedirect=false;
Request. The Method=RequestMethod;
Request. The Timeout=10000;
If (cookies!=null)
{
Request. Headers. The Add (" Cookie ", cookies);
}
The else
{
CookieContainer cookie=new CookieContainer ();
Request. CookieContainer=cookies;
}
Request. The ContentType="application/x - WWW - form - urlencoded";
If (RequestData!=null)
{
Stream RequestStream=request. GetRequestStream ();
Byte [] bytes=Encoding. UTF8. GetBytes (RequestData);
Request. The ContentLength=bytes. The Length;
RequestStream. Write (0 bytes, bytes. The Length).
RequestStream. Close ();
}
HttpWebResponse response=(HttpWebResponse) request. The method GetResponse ();
The string encoding=response. ContentEncoding;
If (encoding==null | | encoding. The Length & lt; 1)
{
Encoding="utf-8";
}
StreamReader reader=new StreamReader (response. GetResponseStream (), Encoding, GetEncoding (Encoding));
String retString=reader. ReadToEnd ();
Request. The Abort ();
Request=null;
//response. The Close ();
//response=null;
TupleTup=new Tuple (retString, response);
Return tup.
}
Catch
{
return null;
}
}
Debug the program execution, will be submitted to the exception: the remote server returns an error: (500) internal server error
Can someone tell me where I went wrong,
CodePudding user response:
Baidu (500) internal server errorCodePudding user response:
Request the interface of the internal handling exceptions, maybe you wrong incoming parameters resulted in the interface when the exception handling, this alignment with interfaceCodePudding user response:
Since 500 an internal error, so you directly debugging and see where the error,CodePudding user response: