Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpWebRequest.Create returns (500) Internal Server Error

It works fine to browse this page : http://www.litteraturmagazinet.se/arga-bibliotekstanten/boklogg/favorit-i-repris-9560835 in a regular browser(for example Chrome).

But when I use the following code to fetch the website I get Internal Server Error (500)?

This is the code I use (and it works great on all other webpages I have tried) :

HttpWebRequest request;
WebResponse webresponse;
request = (HttpWebRequest)HttpWebRequest.Create(url);
webresponse = (HttpWebResponse)request.GetResponse();

The exception is thrown in GetResponse.

I have found for example this : HttpWebRequest.GetResponse() returns error 500 Internal Server Error, but I do not understand it? Why does not request.GetResponse work with this specific webpage? And How do I know what to put in the header(It would be great if it dident hade to be updated later on to diffrent versions)?

like image 952
Banshee Avatar asked Mar 24 '26 11:03

Banshee


1 Answers

I tried your url with wfetch with no headers and i get a 500 as well.

you have to set a proper user-agent in the headers of your request.

HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.contoso.com");
myHttpWebRequest.UserAgent=".NET Framework Test Client";
like image 105
dolomitt Avatar answered Mar 27 '26 01:03

dolomitt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!