Re: HttpWebRequest and Host header (ANSWERED)

From: Feroze [msft] (ferozed_at_online.microsoft.com)
Date: 03/25/05


Date: Fri, 25 Mar 2005 15:38:35 -0800

Yes, this will work. However there is a subtle difference in the request
headers sent with this method, and what the actual request should be
according to RFC.

Using the suggested method, the request that will be sent is this:

GET http://www.company.com/test.aspx HTTP/1.1
Host: www.company.com
<other http headers>

What the RFC expects in this situation in this:

GET /test.aspx HTTP/1.1
Host: www.company.com
<other http headers>

As per RFC Section 5.2:
===
   An origin server that does differentiate resources based on the host
   requested (sometimes referred to as virtual hosts or vanity host
   names) MUST use the following rules for determining the requested
   resource on an HTTP/1.1 request:

   1. If Request-URI is an absoluteURI, the host is part of the
     Request-URI. Any Host header field value in the request MUST be
     ignored.

===

If a server gets a request with an absolute URI, it is supposed to ignore
the host header. Note that although the host header is being ignored, it
will still work because the absolute URI contains the host you want to send
this to.

-- 
feroze
-----------------
This posting is provided as-is. It offers no warranties and assigns no
rights.
See http://weblogs.asp.net/feroze_daud for System.Net related posts.
----------------
"Dave P." <dpurrington.ng@mailnull.com> wrote in message
news:#1$yduXMFHA.3928@TK2MSFTNGP09.phx.gbl...
> Oops.  That should read WebProxy, not CustomWebProxy.
>
> "Dave P." <dpurrington.ng@mailnull.com> wrote in message
> news:u25%23wZXMFHA.1528@TK2MSFTNGP09.phx.gbl...
> > Mark:
> >
> > You can accomplish this by using the Proxy property on HttpWebRequest.
> Use
> > the host header value as the host in your URL.  Then, set your proxy
> object
> > to translate the address to your actual target host.
> >
> > So, using your example:
> > Uri uri = new Uri("http://www.company.com");
> >
> > WebRequest request = WebRequest.Create(uri);
> >
> > request.Proxy = new CustomWebProxy("http://frontend1.east.company.com");
> >
> > request.GetResponse();
> >
> > The end result will be to have the host header of www.company.com , but
> > still be GETting the request from "frontend1.east.company.com"    Keep
in
> > mind that that this code will have all of your requests going to the
same
> > host.
> >
> > Hope that helps,
> > Dave P.
> > (dpurrington.ng2ATmailnullDAHTcom)
> >
> >
> > "Mark" <mmodrall@nospam.nospam> wrote in message
> > news:AD5BD471-3EFE-49B8-A780-91B922E8BE54@microsoft.com...
> > > Hi...
> > >
> > > I've been working a bit with the HttpWebRequest class and one
> requirement
> > > I've gotten recently is the desire to set the HTTP Host: header
> separately
> > > from the specific machine referenced in the url.  For example, the url
> > > http://frontend1.east.company.com
> > > but passing
> > > Host: www.company.com
> > > to emulate a call to the general front door.
> > >
> > > I look in the HttpWebRequest documentation on MSDN, and under the
> Headers
> > > property, it says specifically that the Host header's derived from the
> url
> > > (implying that it can't be overridden).
> > >
> > > Is there any way to do what I want to do?
> > >
> > > Thanks
> > > _mark
> > >
> >
> >
>
>


Relevant Pages

  • Log corruption on multiple webservers, log analyzers,...
    ... Related RFC´s about Internet Host Names convention: ... To succesfully attack a server with “ILLC” technique is mandatory that web ... a machine with a host name as "123.123.123.123" makes a request ... wouldn't appear in the access log file. ...
    (Bugtraq)
  • Re: Book on Pre-MATH for cryptography and cryptanalysis.
    ... There, go request a reform! ... I am reportedly ill, so I host you. ...
    (sci.crypt)
  • Re: DHCP client - Help configuring.
    ... The DHCP server did not pass a host name for this host to use. ... error processing name service request ...
    (comp.os.vms)
  • Re: cgi bin counter
    ... the request did not have a Referer with it so the host would not want ... so the host must have sent ... an Etag with that 0 which is now being used to refresh the old page. ... >>>other types of cgi bin components but not counter! ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: HTTP - basic authentication example.
    ... or *never* knowing the realm..) ... This is called authentication and is implemented ... requests a web page it sends a request to the server. ... consists of headers with certain information about the request. ...
    (comp.lang.python)