HttpWebRequest and WebResponse.GetResponse give incomplete response

spiderman picture spiderman · Jun 21, 2011 · Viewed 8.3k times · Source

I'm pretty RESTless right now because I keep getting incomplete responses from Amazon. I'm using the Product Advertising API, making one ItemLookup request to the server.

The C# code is pretty basic:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse) request.GetResponse();

string resultString;
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
    resultString = sr.ReadToEnd();
}

The number of chars I recieve is 17408- pretty constant but I've seen something around 16k as well.

This is how it always ends:

...ount><CurrencyCode>EUR</CurrencyCode><FormattedPrice>EUR 11,33</FormattedPri

Is there something I don't know about HttpWebRequest or Amazon's API? Please help!

the url (don't care about the key) edit: bad idea, limit exceeded...

Answer

Chris Trombley picture Chris Trombley · Jun 21, 2011

This worked for me:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    HttpWebResponse response = (HttpWebResponse) request.GetResponse();
    Stream s = response.GetResponseStream();
    using (StreamReader sr = new StreamReader(s))
    {
        s.Flush();
        resultString = sr.ReadToEnd();

        ...
    }