Search code examples
.nethttpreflectionhttpwebrequesthost

How to set custom "Host" header in HttpWebRequest?


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?


Solution

  • 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.