开发者

HttpWebRequest setting host to garbage but still getting OK response

开发者 https://www.devze.com 2023-03-20 23:30 出处:网络
I am using an HttpWebRequest and passing in an Address which is an IP.I then set the host to a garbage value.When I call GetResponse() I am getting an OK even though I would expect this to fail since

I am using an HttpWebRequest and passing in an Address which is an IP. I then set the host to a garbage value. When I call GetResponse() I am getting an OK even though I would expect this to fail since the host is garbage.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Format("http://10.10.10.10/Default.aspx"));
request.Host = "blah.blah.blah";
request.ContentType = "text/xml";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
    if (response.StatusCode == HttpStatusCode.OK) { /*always enters here */ }
}

Why is the response coming back as OK? Shou开发者_运维知识库ldn't the garbage host cause this to fail?


HttpWebRequest.Host Property:

Get or set the Host header value to use in an HTTP request independent from the request URI.

Using the Host property to explicitly specify a custom Host header value also affects areas caching, cookies, and authentication. When an application provides credentials for a specific URI prefix, the applications needs to make sure to use the URI containing the value of the Host header, not the target server in the URI.

So there is no effect of .Host to the general request, you change some additional behavior.

0

精彩评论

暂无评论...
验证码 换一张
取 消