获取 WebException 错误中的错误号
如何获取WebException错误中的错误号?
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("site");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
int i = stream.ReadByte();
}
catch (WebException e)
{
//How To Get Error number in WebException Error?
}
How To Get Error number in WebException Error?
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("site");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
int i = stream.ReadByte();
}
catch (WebException e)
{
//How To Get Error number in WebException Error?
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要运行测试以确保它是一个
ProtocolError
:You'll want to run a test to make sure that it was a
ProtocolError
:对于获取错误号:
For Get Error Number:
您可以尝试解析该消息,但并不总是有错误号。例如,超时不会导致 HTTP 错误代码。
You could try to parse the message, but there isn't always an error number. A timeout for example doesn't result in an HTTP error code.