关于HttpWebRequest 遇到404如何避免
关于HttpWebRequest 遇到404如何处理C# codeHttpWebRequest request (HttpWebRequest)(WebRequest.Creat
关于HttpWebRequest 遇到404如何处理
C# codeHttpWebRequest request = (HttpWebRequest)(WebRequest.Create("http://www.baidu.com")); HttpWebResponse response = (HttpWebResponse)request.GetResponse();
HttpWebRequest request = (HttpWebRequest)(WebRequest.Create("http://www.baidu.com")); 这里如果返回403 或者404如何判断呢??由于程序特殊不能使用catch
使用 if (response.StatusCode == HttpStatusCode.OK) 判断使能实现判断 因为执行到WebRequest.Create("http://www.baidu.com")就会报错
[解决办法]HttpStatusCode是个枚举,你看看帮助,都列出来了,404是NotFound,403是Forbidden
[解决办法]if(response.StatusCode == HttpStatusCode.NotFound)
参见
http://msdn.microsoft.com/zh-cn/library/system.net.httpstatuscode.aspx
[解决办法]if(response.StatusCode == HttpStatusCode.NotFound)
if(response.StatusCode == HttpStatusCode.Forbidden)
[解决办法]