开发者

Silverlight: Difficulty with WebClient

I'm having a really weird issue. I must be doing something really obvious that is wrong, but I can't see it. I'm building a wp7 app which currently runs in the emulator.

I have a URL that returns JSON. I visit this URL in my browser and verify that it works.

I get the data from this URL in Silverlight using WebClient. When I get the result, it's all the same - except one of the JSON fields is gone.

How is this possible? I'm not sure what I'm doing wrong. What could cause inconsistencies between the way JSON looks in a web browser v. a WebClient result in the wp7 emulator?

Here's the code:

            downloadData(STORIES_URL + vid,
                delegate(object sender, DownloadStringCompletedEventArgs e)
             开发者_C百科   {
                    data_StoryDownloadCompleted(sender, e, _sectionStories[vid], STORIES_URL + vid);
                });

    static void data_StoryDownloadCompleted(object sender, DownloadStringCompletedEventArgs e, ObservableCollection<Story> results, string uri)
    {
        if (e.Error != null)
        {
            throw e.Error;
        }

        JObject data = JObject.Parse(e.Result);
        // ...
    }

What could I be doing wrong?


Can you capture both requests/responses (from browser and from Silverlight) in a tool like Fiddler and compare them? Specifically, watch for any difference in HTTP headers in the requests.

Then (if you're using Fiddler) you can tweak the Silverlight request by adjusting headers one by one to make it look like the browser request, until you find the one that makes the difference.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜