I have following code written on mono (Mono on ubuntu)
string URI = "http://www.google.com/webmasters/tools/feeds/http%3A%2F%2Fwww%2Ekarkala%2Ein%2F/keywords/?access_token=ya29.ABCDEFGI7bzJmlLWtk290M-PkNx20ej9p6a0sxoaxFPe_7qypXuW7Q";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
request.Headers.Add("GData-Version", "2");
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
The code is part of getting response from Google webmaster API. But I get the following error while trying to get the response
The remote server returned an error: (400) Bad Request.
System at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x00000] in :0 at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00000] in :0
If I copy-paste the same URI on my browser, I am able to see the xml response.
You have to set the request content type:
request.ContentType = "text/xml";
Otherwise, the remote server won't know what to do with your request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With