문제

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