Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpWebRequest and WebResponse.GetResponse give incomplete response

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...

like image 247
spiderman Avatar asked Oct 24 '22 08:10

spiderman


1 Answers

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();

        ...
    }
like image 89
Chris Trombley Avatar answered Oct 31 '22 10:10

Chris Trombley