WebRequest.GetResponse gives "Bad Request"

M

Mange

I'm using WebRequest class to access a PHP script, but keep getting a
400 error from the server when calling the GetResponse() method.

I have added the url to the script in the bypass list in machine.config
to bypass the proxy server for this request, so it should not be a
proxy issue. Also, I tried to run the same code in a Windows app, to
see if it had to do with user credentials but no luck there.
The script can be accessed with IE without any problem, so there is a
way to get to the script, I just can't get ASP.Net to do it...

This is the code:

HttpWebRequest StockRequest =
(HttpWebRequest)WebRequest.Create("http://urltomyscript/scriptname.php");
StockRequest.Timeout = 10000; //10 seconds
HttpWebResponse StockResponse =
(HttpWebResponse)StockRequest.GetResponse();

Regards,
Mange
 
J

John Timney \( MVP \)

also, have you tried any other URL to see if your code is working
 
J

Joerg Jooss

Hello Mange,
I'm using WebRequest class to access a PHP script, but keep getting a
400 error from the server when calling the GetResponse() method.

I have added the url to the script in the bypass list in
machine.config
to bypass the proxy server for this request, so it should not be a
proxy issue. Also, I tried to run the same code in a Windows app, to
see if it had to do with user credentials but no luck there.
The script can be accessed with IE without any problem, so there is a
way to get to the script, I just can't get ASP.Net to do it...
[...]

Use a HTTP proxy like Fiddler to compare a working request sent by a browser
with your HttpWebRequest.

Cheers,
 

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