views:

64

answers:

1
    string url = "http://foo.com/bar?id=" + id + "&more=" + more;
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

I m trying make a call to another server, and getting back the following:

 |FATAL|The remote server returned an error: (406) Not Acceptable. (REF #1)
System.Net.WebException: The remote server returned an error: (406) Not Acceptable.

Why am i getting this error? and how to fix this?

+1  A: 

According to the RFC

10.4.7 406 Not Acceptable

The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.

Review the accept headers that your request is sending , and the content server in that URL ; )


BONUS

  • To see the accept headers: browse to the URL and use FireBug (HTML tab).

  • To set the accept headers into your request use the HttpWebRequest Members.

SDReyes
so you are saying that i should just invoke it, not expect any response?
Whoops, I just finished to update the answer : )
SDReyes
oh so you are saying that parameters are not acceptable?
Hi User177883 (you have to set your nick ; ) hehehe, what kind of resource is being served in that URL (an image, a HTML page, it's a web service maybe)?
SDReyes
i m just invoking the url with the parameters, that sit.
Hi again!, can you browse to the URL? (including the parameters you're passing)
SDReyes
yes, and response is blank when i invoke the url.
Use firebug to get the HTTP headers you're sending to the server. Then set them manually to the HttpWebRequest object - see the MSDN article http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest_members%28VS.80%29.aspx Tell me if it works : )
SDReyes