How can I set a custom Host header in HttpWebRequest? I know that normally this class doesn't allow you to do so but is there anyway to use reflection or something like that without actually need me to send the whole packet with TCPClient?
相关问题
- Angular RxJS mergeMap types
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- C# how to invoke a field initializer using reflect
- 'System.Threading.ThreadAbortException' in
相关文章
- C#使用http访问网络,有办法用指定网卡访问网络嘛?
- .net中MessageBox.Show使用问题
- IdentityServer 报错:"idp claim is missing"
- 在 IdentityServer 中如何给 id token 添加更多信息
- IdentityServer 的 Selector 在哪个 nuget 包
- 使用 IdentityServer 的项目遭遇错误:"IDX20803: Unable to obt
- ASP.NET Core ConfigureServices 中从 appsettings.json
- .netCore 控制台程序输出配置问题
Necromancing.
For those still on .NET 2.0
It is in fact quite easy, if you know how.
Problem is, you can't set the host header, because the framework won't let you change the value at runtime. (.net framework 4.0+ will let you override host in a httpwebrequest).
Next attempt will be setting the header with reflection, to get around it, which will let you change the header value. But at runtime, it will overwrite this value with the host part of the url, which means reflection will bring you nothing.
If the dns-name doesn't exist, which is quite frankly the only case in which you want to do this in the first place, you can't set it, because .NET can't resolve it, and you can't override the .NET DNS resolver.
But what you can do, is setting a webproxy with the exact same IP as the destination server.
So, if your server IP is 28.14.88.71:
and voila, now
and you get the correct page back, if 28.14.88.71 is a webserver with virtual name-based hosting (based on http-host-header).
WebClient allows it.
I couldn't tell you why. The documentation clearly states that Host is a system header.
There is a roundabout way to do this, as described here:
http://blogs.msdn.com/feroze_daud/archive/2005/03/31/404328.aspx
However, the next version of the framework (.NET Framework 4.0) will make it easier.
http://blogs.msdn.com/ncl/archive/2009/07/20/new-ncl-features-in-net-4-0-beta-2.aspx
Hope this helps.
you can use proxy, see my answer at: Request Web Page in c# spoofing the Host
You can use this hack, designed for solve this problem in .Net 3.5 .