404 error with WebClient request

  • Thread starter Thread starter Tony B
  • Start date Start date
T

Tony B

Hi,
When I make a request for a web page using the System.Net.WebClient class
I'm getting a page not found (404) error for a webpage that I know exists.

Here's the relevent bit of code:

aRequestedHTML = objWebClient.DownloadData(strUrl)
strRequestedHTML = objUTF8.GetString(aRequestedHTML)

aRequestedHTML is a byte array, strUrl is a full url such as
http://10.0.1.6/categories/index.asp and strRequestedHTML is the output of
the request.

The exception I get is:

WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at Neop.Module1.ReadWebPage(String strUrl)

The webserver is on the same machine the application runs on. I know the url
exists as I can see it in a browser. Also if I run the application from a
different machine I don't get any errors and the HTML for the page is
returned.

Anyone got any ideas?

Tony
 
Hi Tony,

Mostly a sucurity isue but which one I would not know, try the newsgroup
framework security and adonet also, probably there you have a better change.

Although I would try it if it is a local computer with 127.0.0.1 or
localhost also.


Cor
 
I think I've solved my own problem, I'm posting the solution here in case
anyone searching at Google Groups later has encountered the same problem.

It seems that the WebClient class doesn't work as expected if it's requests
go to a
local web server with a request to an IP address. I've added the IP address
to my local hosts file with a host name. I changed my application so that it
used the host name in place of the IP address and everything worked.

Tony
 
Tony,
Just a guess but could this be a DNS issue. What if you replace
the IP address with the 127.0.0.0, does this make any difference when
calling it programitically.

Alternatively, try putting an entry for your machine in the hosts file and
calling the URL by name rather than by IP address to see if this helps.

Regards - OHM
 
Three in a row, but almost the same thought and so fast we cannot type and
send that we did see it from each other

:-))
 
Tony,
It looks as if I was heading in the right direction then as you
see I suggested this in my reply to you before you posted this one.

Regards - OHM
 
One Handed Man said:
Tony,
It looks as if I was heading in the right direction then as you
see I suggested this in my reply to you before you posted this one.

Regards - OHM

Looks like great minds think alike!

My second post appeared at the same time as your first one! Same time stamp
in my newsreader.

Thanks for your input.

Tony
 
Hi Herfried,

I did not see comments on that Beer message/answer from me, where I wrote
that for you would be better Villacher or Urquel, what is it in Wien?

Cor

PS for me is Urquel from fust in the Pilsen area the best beer I know (not
in a bottle).
 
* "Cor said:
I did not see comments on that Beer message/answer from me, where I wrote
that for you would be better Villacher or Urquel, what is it in Wien?

Mhm... I missed the tread...
PS for me is Urquel from fust in the Pilsen area the best beer I know (not
in a bottle).

Pilsner Urquell is ver good, Budweiser is good excellent too. I never
drank Villacher.

;-)))
 
Back
Top