Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / October 2004

Tip: Looking for answers? Try searching our database.

Setting host header for WebRequest

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Subir - 30 Sep 2004 17:51 GMT
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
Joerg Jooss - 30 Sep 2004 20:17 GMT
> 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.

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,

Signature

Joerg Jooss
joerg.jooss@gmx.net

Subir - 01 Oct 2004 08:07 GMT
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

> > Hi,
> > I am using the WebRequest class to access a web site. The web site is
[quoted text clipped - 16 lines]
>
> Cheers,
Joerg Jooss - 01 Oct 2004 09:02 GMT
> 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?

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?

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

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,

Signature

Joerg Jooss
joerg.jooss@gmx.net

Subir - 01 Oct 2004 18:37 GMT
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

> > thanks...
> > if I have 2 web sites on the same machine which differ only by host
[quoted text clipped - 17 lines]
>
> Cheers,
Joerg Jooss - 02 Oct 2004 08:56 GMT
> 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?

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,

Signature

Joerg Jooss
joerg.jooss@gmx.net

Subir - 04 Oct 2004 19:23 GMT
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

> > 1. You are right, I will not be abe to access it through the browser till
> > I
[quoted text clipped - 15 lines]
>
> Cheers,
Joerg Jooss - 08 Oct 2004 18:32 GMT
> 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
[quoted text clipped - 3 lines]
> websites? I can assume that the exe will be executed on the same
> machine as the site.

Subir,

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

Cheers,

Signature

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.