The HTTP request service was used yesterday to create an HTTP connection using httpwebrequest.
The result is always abnormal when the server response status is obtained. The following code shows the exception:
try { HttpWebRequest request = ar.AsyncState as HttpWebRequest; HttpWebResponse response = request.EndGetResponse(ar) as HttpWebResponse; using (var stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream); string msg = reader.ReadToEnd(); } } catch (Exception e) { string a = e.ToString(); }
In execution
HttpWebResponse response = request.EndGetResponse(ar) as HttpWebResponse;
An exception is reported in this statement:
Remote Server returned an error: notfound.
I still cannot solve this problem by referring to some documents.
After adjusting the parameters in the POST request, the returned status code is 200.
The main reason is that the server has some specific requirements on the post parameter field, such as the length required or the field that cannot be omitted.
The strange thing is that if a parameter error occurs, the received status code should be 601 (the status code defined by the server, which is an invalid parameter), but it directly throws an exception; however, the enumerated quantity in httpstatuscode does not have this value (2XX to 5xx). I don't know if this problem causes an exception.