all groups > dotnet sdk > september 2004 >
You're in the

dotnet sdk

group:

Setting host header for WebRequest


Setting host header for WebRequest Subir
9/30/2004 9:51:03 AM
dotnet sdk:
Hi,
I am using the WebRequest class to access a web site. The web site is not
configured in the DNS. So I want to set the host header value in the request
object. Any ideas how I can do this?
I do not have the option of updating the hosts file and then accessing the
site.

Thanks,
Subir
Re: Setting host header for WebRequest Joerg Jooss
9/30/2004 9:17:11 PM
[quoted text, click to view]

HttpWebRequest sets the Host header implicitly. Trying to set it should
result in an ArgumentException.

In your case it doesn't make sense anyway. If the site is only known by IP
address, the Host header *should* contain the same IP address. Something
like

GET http://207.46.157.188/ HTTP/1.1
Host: www.microsoft.com

violates AFAIK the HTTP 1.1 spec.

Cheers,

--
Joerg Jooss
joerg.jooss@gmx.net

Re: Setting host header for WebRequest Subir
10/1/2004 12:07:03 AM
thanks...
if I have 2 web sites on the same machine which differ only by host header
name then how do i access each site though code? Since the site is not
configured in the DNS I have to use the IP. However only using the IP will
fail since both my sites are on the same IP.
my understanding may also be terribly wrong.

Subir

[quoted text, click to view]
Re: Setting host header for WebRequest Joerg Jooss
10/1/2004 10:02:54 AM
[quoted text, click to view]

I wonder how you access the site at all. Since you enter the "Host" in a
browser's URL field, there's no way to connect to the server -- or am I
missing something here?

[quoted text, click to view]

HTTP 1.1, section 14.23 says
"The Host request-header field specifies the Internet host and port number
of the resource being requested, as obtained from the original URI given by
the user or referring resource"

which implies what I've said before -- your construct isn't supported.

Cheers,

--
Joerg Jooss
joerg.jooss@gmx.net

Re: Setting host header for WebRequest Subir
10/1/2004 10:37:04 AM
1. You are right, I will not be abe to access it through the browser till I
add an entry in my hosts file or in the DNS. So does it imply that even
through code I have the same restriction?
2. Got it!

Thanks again
Subir

[quoted text, click to view]
Re: Setting host header for WebRequest Joerg Jooss
10/2/2004 9:56:26 AM

"Subir" <Subir@discussions.microsoft.com> schrieb im Newsbeitrag
news:44E75FC8-FACA-4994-A66C-DA320B00471C@microsoft.com...
[quoted text, click to view]

Interesting question. I guess the following could even work, but it requires
plain sockets (see System.Net.Sockets.Socket or
System.Net.Sockets.TcpClient):

1. Connect to your web server's socket.
2. Send a HTTP request with a non-absolute URI and a Host header, i.e.

GET /path/to/doc.htm HTTP/1.1
Host: www.foo.org

But this is nothing more but a technical experiment. What's the point in
hosting an inaccessible web server?

Cheers,

--
Joerg Jooss
joerg.jooss@gmx.net

Re: Setting host header for WebRequest Subir
10/4/2004 11:23:04 AM
The application is executed right after the website is installed by an msi.
The exe sends a request to the site and checks the response to certify if the
website is installed correctly. Earlier I was creating vroots instead of
websites and the WebRequest was serving me fine. Can you give some suggestion
how I can achieve the same for websites? I can assume that the exe will be
executed on the same machine as the site.

Thanks,
Subir

[quoted text, click to view]
Re: Setting host header for WebRequest Joerg Jooss
10/8/2004 7:32:39 PM
[quoted text, click to view]

Subir,

sorry, I'm somewhat confused. Does this question still relate to the
previous discussion?

Cheers,

--
Joerg Jooss
www.joergjooss.de
news@joergjooss.de

AddThis Social Bookmark Button