I'm trying to download a JSON from Twitter with all the authorization and stuff.

WebClient wc = new WebClient();
wc.DownloadStringCompleted += (b, a) => {
    if (a.Cancelled)
        MessageBox.Show("Download Canceled!");
    else if (a.Error != null)
        MessageBox.Show("Download Error!");
    else
        string g = a.Result;
};
wc.DownloadStringAsync(new Uri("TWITTER_JSON"));

(TWITTER_JSON is a long address with many authorization headers that gives the JSON)
When I run this the 2nd message ("Download Error!") shows up. Why? And how do I fix this?

有帮助吗?

解决方案

a.Error is actually an Exception object. Have you tried examining it to see what the exception details contain?

MessageBox.Show( a.Error.ToString() );

That will give you more information about what actually went wrong.

You may also find it helpful to read Eric Lippert's recent blog post on how to debug your code.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top