5

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?

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

starball
  • 20,030
  • 7
  • 43
  • 238
spiderman
  • 151
  • 2
  • 9

1 Answers1

3

This worked for me:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    WebResponse response = request.GetResponse();
    Stream s = response.GetResponseStream();
    using (StreamReader sr = new StreamReader(s))
    {
        s.Flush();
        resultString = sr.ReadToEnd();
        
        ...
    }
Chris Trombley
  • 2,232
  • 1
  • 17
  • 24
  • Now I've got it. The problem was solved by flushing but in several places in my code. ;) Thanks to all. – spiderman Jun 21 '11 at 20:21
  • I have a similar problem. I tried to Flush the stream, but doing so gives me a NotSupportedException. Any idea how to solve that? – Thizzer Jun 22 '11 at 18:31
  • 1
    You may skip cast ```WebReponse``` to ```HttpWebResponse``` due to ```GetResponseStream``` is method of ```WebResponse``` class. – isnullxbh Jun 27 '19 at 12:21