开发者

WPF - Web Request being truncated

I'm using the bing api to request some results.. when I run my code the response string is truncated so that its missing the first 10-50 characters.. when I paste the exact same request in the browser it returns the results just fine..

Here is my code.. what am I doing wrong?

            string AppId = "My APP ID HERE :O ";
        string url = "http://api.search.live.net/xml.aspx?Appid={0}&sources={1}&query={2}";
        string completeUri = String.Format(url, AppId, "web", validateforweb(Artist) + "%20" + validateforweb(Song) + "%20" + "Lyrics");
        HttpWebRequest webRequest = null;
        webRequest = (HttpWebRequest)WebRequest.Create(completeUri);
        HttpWebResponse webResponse = null;
        webResponse = (HttpWebResponse)webRequest.GetResponse();
        XmlReader xmlReader = null;
        Stream s = webResponse.GetResponseStream();
 开发者_如何转开发       xmlReader = XmlReader.Create(s);
        StreamReader reader;
        reader = new StreamReader(s);
        string str = reader.ReadToEnd();


I suspect it's related to the fact you're creating 2 readers on the stream (XmlReader and StreamReader). The XmlReader starts buffering data from the stream as soon as you create it, so when the StreamReader starts reading from the same stream, it misses the part of the data that has been buffered by the XmlReader.

You can't use 2 readers on the same stream, they will conflict with each other.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜