Home > Net >  C # postman debugging success, writes application error
C # postman debugging success, writes application error

Time:12-16

Can I use the postman debugging requests a web page address debugging success
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 Tuple UrlRequest (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;
Tuple Tup=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 error

CodePudding 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 interface

CodePudding user response:

Since 500 an internal error, so you directly debugging and see where the error,

CodePudding user response:

refer to the third floor is nu month god reply:
since 500 internal error, then you directly debugging to see where an error,

Website is certainly no problem, after all, postman can debug successful, this method must be problem of a class, just don't know where is there a problem

CodePudding user response:

refer to the second floor car networking _ salted fish response:
request interface internal handling exceptions, maybe you wrong incoming parameters resulted in the interface when the exception handling, this alignment with interface
interface, I cannot change, the incoming parameters like the postman is the same, the difference is that the postman is key: the form of value, enter a connector, and program class is the key=value, & amp; As a connector,
Such as the body part of the postman is
The program class RequestData travels is username=test& Password=pass

CodePudding user response:

The
reference 4 floor mio mountain true seeker reply:
Quote: refer to the third floor is nu month god reply:
since 500 internal error, then you directly debugging to see where an error,

Website is certainly no problem, after all, postman can debug successful, this method must be problem of a class, just don't know where there are problems

Change the way,
https://blog.csdn.net/hanjun0612/article/details/60126445

CodePudding user response:

Use Fiddler requests of the network monitoring, and see the difference between two ways

CodePudding user response:

Data types are not
  •  Tags:  
  • C#
  • Related