HttpWebRequest.GetResponse returns 404 No Found error

W

warlord

I have a windows client app that is trying to download a file from
a web server but I always get the following error when I call the
GetResponse method of the Request object.

The remote server returned an error: (404) Not Found.

When I run it against a website on my local machine everything works
perfectly, but not against the remote server. I'm sure it's a security
or permissions problem of some sort, but I'm not sure where to start.

The code I'm using is below.

Thanks in advance for any help.

Cameron


HttpWebResponse Response;

//Retrieve the File
HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create(url);
Request.Headers.Add("Translate: f");
Request.Credentials = CredentialCache.DefaultCredentials;

try
{
Response = (HttpWebResponse)Request.GetResponse();
}
catch(WebException e)
{
//Handle the exception here
}
finally
{
Response.Close()
}
 
K

Ken Schaefer

Is the remote server an IIS 6.0 box? If so, is WebDAV enabled?
Does the URL requested actually exist?

Cheers
Ken

: I have a windows client app that is trying to download a file from
: a web server but I always get the following error when I call the
: GetResponse method of the Request object.
:
: The remote server returned an error: (404) Not Found.
:
: When I run it against a website on my local machine everything works
: perfectly, but not against the remote server. I'm sure it's a security
: or permissions problem of some sort, but I'm not sure where to start.
:
: The code I'm using is below.
:
: Thanks in advance for any help.
:
: Cameron
:
:
: HttpWebResponse Response;
:
: //Retrieve the File
: HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create(url);
: Request.Headers.Add("Translate: f");
: Request.Credentials = CredentialCache.DefaultCredentials;
:
: try
: {
: Response = (HttpWebResponse)Request.GetResponse();
: }
: catch(WebException e)
: {
: //Handle the exception here
: }
: finally
: {
: Response.Close()
: }
:
:
 
W

warlord

The web server is IIS 5.0, and the Url does exist. I can get to it via a
browser without any problems - it's just from within the windows app that it
isn't accessible.

Cheers,

Cameron
 
J

John Timney \(Microsoft MVP\)

Could it be that you go through a proxy server normally, and your windows
app is not providing the proxy credentials?

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
 
G

George Ter-Saakov

The browser reports the HTTP_REFERRER to the server.
And a lot of servers prevent downloading images if HTTP_REFERRER points to
different server name.

Thus preventing so called "hotlinking". When someone else site links to the
images that reside on someone else's server.

So they do not need to pay for bandwidth.

George.
 
W

warlord

I thought that might be the case, but I'm providing the proxy credentials
and still no joy. In fact, I get the same error whether I provide them or
not, and when I run everything locally it works whether I provide the proxy
credntials or not.

Regards,

Cameron
 
W

warlord

I probably should add that the same windows application calls a web service
one the server without any problems - it's only trying to get the Response
stream from a new Request object.

Cheers,

Cameron
 
J

John Timney \(Microsoft MVP\)

Does the app your calling expect cookies, I'm guessing that your web service
is stateless but your web app is not. It may be trying to establish a
session and failing.

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
 
W

warlord

John,
The web service is actually using session state (I'm not entirely sure why
as I didn't write the service...in fact I didn't write any of it, I'm just
the luck SOB who got the job of debugging it and finishing it off) and of
course the web application is also using session state.

I have even added a separate web.config file to the folder containing the
files I'm trying to get to that explicitly sets the session state settings
(not that I need to do that) but also overrides the authenticaton and
authorization settings to use Windows authentication (impersonate is set to
true) and to allow all users - all to no avail.

Interestingly, if I disable session state for the web application the home
page still displays as it is not reliant on session at all, but when I
navigate to a page that uses session state the error I receive is the 404 -
Not Found error. Your previous reply and this is what prompted me to try
the separate config files.

I've also set the cookieless element of the sessionState setting to true but
that too makes no difference.

Any further suggestions ?

Thanks for all your help so far.

Regards,

Cameron Gibbs
 
J

John Timney \(Microsoft MVP\)

The web service is actually using session state (I'm not entirely sure why
as I didn't write the service...in fact I didn't write any of it, I'm just
the luck SOB who got the job of debugging it and finishing it off) and of
course the web application is also using session state.


if thats the case, then your winforms app needs to handle the cookie asp.net
generates when you connect to the server. The server will expect the
session cookie to be passed back to it.


--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
 
W

warlord

Have you got any examples of doing this ? I've set the
Request.CookieContainer to a new CookieContainer before calling
Request.GetResponse but the same error occurs. You mention the app needs to
handle the cookie that asp.net generates when it connects to the server, but
I don't seem to be able to connect to the server without getting the error.

Regards,

Cameron Gibbs
 
W

warlord

Well I've almost got to the bottom of the problem....The IIS Lockdown
utitlity had been run on the server (which I was not made aware of) and
there were two things preventing my app from working correctly.

Firstly the UrlScan utitlity was preventing the request from getting
through, hence the 404 Not Found error. Exactly what changes I need to make
to the UrlScan INI file I'm not yet sure, but at least I know the root of
the problem lies there.

Secondly, WebDAV had been disabled. This wasn't the cause of the 404 Not
Found error, but still needed enabling anyway. With this disabled (and
UrlScan not running at all) I got a 501 Not Implemented error.

So thanks to Ken pointing me in theright direction, WebDAV is now enabled.
All I have to do now is figure out the changes to UrlScan

Cheers,

Cameron
 
W

warlord

I figured out that the 'translate' header must be allowed through UrlScan,
and also the PROPFIND verb. My UrlScan configuration was denying both of
these and was the root of the problem.


Cameron
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,088
Latest member
JeremyMedl

Latest Threads

Top