Asp.net HttpWebResponse“;请参阅“其他”;返回的状态码不是404
我正在做一个web请求,它应该返回一个404状态码,因为URL不存在,但它返回的是303(参见其他)状态。如果我查看它返回的URL作为重定向URL,它是: 有人知道我如何防止这一点,并看到原始404没有openDNS重定向劫持它 我的代码:Asp.net HttpWebResponse“;请参阅“其他”;返回的状态码不是404,asp.net,httpwebrequest,http-status-code-404,httpwebresponse,Asp.net,Httpwebrequest,Http Status Code 404,Httpwebresponse,我正在做一个web请求,它应该返回一个404状态码,因为URL不存在,但它返回的是303(参见其他)状态。如果我查看它返回的URL作为重定向URL,它是: 有人知道我如何防止这一点,并看到原始404没有openDNS重定向劫持它 我的代码: // create the HttpWebRequest object HttpWebRequest request = WebRequest.Create("www.googuaoeuaoeu23p2le.com") as
// create the HttpWebRequest object
HttpWebRequest request = WebRequest.Create("www.googuaoeuaoeu23p2le.com") as HttpWebRequest;
// don't allow redirect
request.AllowAutoRedirect = false;
request.Method = "GET";
request.AllowWriteStreamBuffering = true;
request.KeepAlive = false;
request.ContentType = "application/x-www-form-urlencoded";
request.SendChunked = false;
request.Credentials = CredentialCache.DefaultCredentials;
request.UserAgent = "NetMonitor";
// set the timeout
request.Timeout = 5000;
// get the data as an HttpWebResponse object
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
// convert the data into a string (assumes that we are requesting text)
StreamReader responseReader = new StreamReader(response.GetResponseStream());
// get HTML from the response
string responseHTML = responseReader.ReadToEnd();
// close the response reader
responseReader.Close();
// at this point we successfully got a response and just need to determine what type -- get status code
HttpStatusCode statusCode = response.StatusCode;
不使用OpenDNS?这是一个轻率的回答,但这是使用OpenDNS的缺点。它们从不返回webclient检测404所不需要的主机 尽管如此,如果您从OpenDNS获得响应,这意味着您的客户端无法找到服务器。404一旦连接到服务器,它就来自服务器&它找不到您请求的资源 您需要先更改代码以执行DNS查找-在System.Net中查找dnslookup类-如果查找失败,则返回404 现在实际发生的是:
- 您的webclient对提供的主机名执行dns查找
- dns查找失败
- OpenDNS拦截故障并返回其服务器的IP地址
- 然后,他们的服务器返回对初始主机名的搜索响应以及延续代码
- 您对主机名执行dns查找
- 主机不存在,因此返回404
- 您对主机名执行dns查找
- 主机存在,因此您可以发出请求
- 主机找不到请求的路径,因此返回404
- 你返回404
- 您对主机名执行dns查找
- 主机存在,因此您可以发出请求
- 路径存在,主机返回请求的数据
- 你把这个还给你的客户