IP address no good for WebClient Url?

B

Bryan

When I try to get a web page from an internal server, I have success
when I use the DNS name, but not when I use the raw IP address. The
first example works, the second does not. Why is this?

Example 1
--------------------------------------------------------------------------------------------------
' Get web page
Dim url As String = "http://brysrv:5004/"
Dim client As WebClient = New WebClient
Dim data As Stream = client.OpenRead(url)
Dim reader As StreamReader = New StreamReader(data)
Dim str As String = reader.ReadToEnd
reader.Close()
Console.WriteLine(str)

Example 2
--------------------------------------------------------------------------------------------------
' Get web page
Dim url As String = "http://10.0.45.67:5004/"
Dim client As WebClient = New WebClient
Dim data As Stream = client.OpenRead(url)
Dim reader As StreamReader = New StreamReader(data)
Dim str As String = reader.ReadToEnd
reader.Close()
Console.WriteLine(str)
 
O

Onur Güzel

When I try to get a web page from an internal server, I have success
when I use the DNS name, but not when I use the raw IP address. The
first example works, the second does not. Why is this?

Example 1
--------------------------------------------------------------------------------------------------
' Get web page
Dim url As String = "http://brysrv:5004/"
Dim client As WebClient = New WebClient
Dim data As Stream = client.OpenRead(url)
Dim reader As StreamReader = New StreamReader(data)
Dim str As String = reader.ReadToEnd
reader.Close()
Console.WriteLine(str)

Example 2
--------------------------------------------------------------------------------------------------
' Get web page
Dim url As String = "http://10.0.45.67:5004/"
Dim client As WebClient = New WebClient
Dim data As Stream = client.OpenRead(url)
Dim reader As StreamReader = New StreamReader(data)
Dim str As String = reader.ReadToEnd
reader.Close()
Console.WriteLine(str)

Bryan,
Normally both of them should work (defining URI as address and as IP).
To test, try getting Google's data as examle as follows:

' Both works:
Example 1 works with using an IP as string
-------------------------------------
' Get web page
' That IP belongs to Google
Dim url As String = "http://74.125.77.104/"
Dim client As WebClient = New WebClient
Dim data As Stream = client.OpenRead(url)
Dim reader As StreamReader = New StreamReader(data)
Dim str As String = reader.ReadToEnd
reader.Close()
Console.WriteLine(str)


Example 2 for Google again which works with absolute web path:
--------------------------------------------
' Get web page
Dim url As String = "http://www.google.com"
Dim client As WebClient = New WebClient
Dim data As Stream = client.OpenRead(url)
Dim reader As StreamReader = New StreamReader(data)
Dim str As String = reader.ReadToEnd
reader.Close()
Console.WriteLine(str)


So, i think, just by looking at your code, in your example 2, it seems
you're trying to access an IP which resides on a restricted LAN area,
that is is needed to be forwarded through a router setting or kinda. I
beleive, if you set required rights and especially forward that IP
address with port 5004, you problem should be solved based on my
previous experiences.

HTH,

Onur Güzel
 
A

Andrew Morton

Bryan said:
When I try to get a web page from an internal server, I have success
when I use the DNS name, but not when I use the raw IP address. The
first example works, the second does not. Why is this?

Is the web server using host headers for brysrv? That could stop a URL
written as the IP address from working.

Andrew
 
B

Bryan

Is the web server using host headers for brysrv? That could stop a URL
written as the IP address from working.

Andrew

The strangest thing is that I could connect to 10.0.45.67:5004 just
fine in my web browser. That's when I realized that maybe .Net is
pulling me internet settings from Internet Explorer. I use Firefox as
a browser, and it worked fine there. I checked my IE settings and saw
that I still had a proxy set up. I deleted the proxy settings and it
works now. I'm assuming that .Net uses IE internet settings?
 
O

Onur Güzel

The strangest thing is that I could connect to 10.0.45.67:5004 just
fine in my web browser.  That's when I realized that maybe .Net is
pulling me internet settings from Internet Explorer.  I use Firefox as
a browser, and it worked fine there.  I checked my IE settings and saw
that I still had a proxy set up.  I deleted the proxy settings and it
works now.  I'm assuming that .Net uses IE internet settings?

Byran,
As stated in that link:
"The proxy is set by the system using configuration files and the
Internet Explorer Local Area Network settings" in WebClient.Proxy
property's documentation:
http://msdn.microsoft.com/en-us/library/system.net.webclient.proxy(VS.80).aspx

And also: "To specify that no proxy should be used, set the Proxy
property to the proxy instance returned by the GetEmptyWebProxy
method." seems stated.
GetEmptyWebProxy method:
http://msdn.microsoft.com/en-us/library/system.net.globalproxyselection.getemptywebproxy(VS.80).aspx

Hope that clarifies,

Onur Güzel


And also you stated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top