473,388 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

404 error with WebClient request

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(IAsyncRes ult 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
Nov 20 '05 #1
10 10983
Cor
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'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 > 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(IAsyncRes ult 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.

Nov 20 '05 #2
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


Nov 20 '05 #3
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
Tony B wrote:
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(IAsyncRes ult 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

Nov 20 '05 #4
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
Tony B wrote:
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

Nov 20 '05 #5
Cor
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

:-))
Nov 20 '05 #6
* "Cor" <no*@non.com> scripsit:
framework security and adonet also, probably there you have a better change.


Just FMI: ADO.NET or ASP.NET?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #7

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bq**********@titan.btinternet.com...
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
Nov 20 '05 #8
Cor
Asp.net you are right mistake of me while typing

:-))
Nov 20 '05 #9
Cor
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).
Nov 20 '05 #10
* "Cor" <no*@non.com> scripsit:
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.

;-)))

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Justin Malloy | last post by:
I am using the System.Net.Webclient to try and download an XML file from a website but am receiving a HTTP protocol error when running the DownloadFile() sub routine. I did a HTTP trace using...
6
by: genc ymeri | last post by:
Hi, We are struggeling to upload a file through a C# webClient into JBoss web server. Meanwhile we are able to upload a file from the webserver itself. The problem is only with C# webClient . The...
1
by: Jason Manfield | last post by:
What is the difference (pros and cons) between retrieving data from the web using System.Web.WebClient and using HttpWebRequest and Response to get the data? The WebClient download methods seem to...
4
by: Grant Harmeyer | last post by:
When I try to upload a file to a resource on my local webserver, my code catches an exception that a 405 error (method not supported) has occured on the server. I set the code up nearly exactly as...
6
by: Dave Starman | last post by:
Hello, I am trying to download web data into my current application. Failing many attempts I tried to run the sample from the MS Help files with no luck. If I create a new solution and put the...
0
by: Saverio Tedeschi | last post by:
Hi all gurus, forgive me if I submit a 2nd post, but I'm no more able to see my question. So: I wrote an Win app with embedded FTP client (well, made some cut and paste from others' projects :-))...
1
by: Pedro Carvalho | last post by:
I am using a WebClient.Upload File method on the Client side and, to accept posted files on the Server side, I am using an ASP.NET page with the following code: void Page_Load(object sender,...
4
by: Lehel Kovach | last post by:
I'm having a problem with the WebClient object. When I post data to certain sites, it will receive a command from the webserver (object moved) and continue to the next link by downloading that. ...
3
by: Giggi | last post by:
Hi! I need to pass some strings via an HTTP POST from page1 (in my app) to a page on another server. I stored my data in a NameValueCollection and then sent it using WebClient.UploadValues....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.