0

ASP.NET returned an error: (406) Not Acceptable.

Hi There;

Cutting this down to bare bones I have a aspx page (.Net 3.5 running at localhost under IIS 7) with the following:

CODE
protected void Page_Load(object sender, EventArgs e)
{
HttpWebRequest request = WebRequest.Create("http://where.yahooapis.com/v1/place/1/children?appid=[myAppId]) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
myxml.DocumentContent = response.GetResponseStream().ToString();
}
}


I have checked the URL in a browser and it works fine, (with myAppId replaced). But when this code runs in my aspx page the error returned is:

QUOTE
The remote server returned an error: (406) Not Acceptable.


With the error in the line:

CODE
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)


Can anyone help me to see what's wrong with this?

Thanks in advance;

-Pete

by
2 Replies
  • I have discovered that I get the same error when using an equivalent script in PHP using http://developer.yahoo.com/php/samples/par...seSIMPLEXML.txt

    QUOTE
    PHP Warning: file_get_contents(http://where.yahooapis.com/v1/place/1/children?appid=[myAppId]) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: HTTP request failed! HTTP/1.1 406 Not Acceptable
    in \localhost\phpDev\yahooTest.php on line 12


    Hope this helps.

    -Pete
    0
  • So it turned out the problem was the accept type.

    request.Accept="application/xml";

    See fixed code below:

    CODE
    protected void Page_Load(object sender, EventArgs e)
    {
    HttpWebRequest request = WebRequest.Create("http://where.yahooapis.com/v1/place/1/children?appid=[miAppId]") as HttpWebRequest;
    request.Accept="application/xml";

    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
    Stream stream = response.GetResponseStream();

    XmlTextReader reader = new XmlTextReader(stream);
    reader.WhitespaceHandling = WhitespaceHandling.None;
    reader.Read();

    XPathDocument xDocument = new XPathDocument(reader);

    response.Close();

    myxml.XPathNavigator = xDocument.CreateNavigator();
    }
    }


    Hope this helps someone else.

    Cheers

    -Pete
    0
This forum is locked.

Recent Posts

in GeoPlanet General Discussion