0
public static Task<string> GetData(string url, string data)
{
UriBuilder fullUri = new UriBuilder(url);
if (!string.IsNullOrEmpty(data))
fullUri.Query = data;
WebClient client = new WebClient();
var tcs = new TaskCompletionSource<string>();
client.DownloadStringCompleted += (s, args) =>
{
if (args.Error != null)
tcs.TrySetException(args.Error); // HERE
else if (args.Cancelled)
tcs.TrySetCanceled();
else
tcs.TrySetResult(args.Result);
};
client.DownloadStringAsync(fullUri.Uri);
return tcs.Task;
}
地,上述方法在“//这里的”进入错误...TaskCompletionSource抛出错误,但不知道为什么
的事情是,我相信,网址和参数是正确的。除了创建我自己的API页面之外,我应该首先检查哪些典型的东西?
它在'InnerException'中说:'远程服务器返回一个错误:NotFound。“所以,你走了,这是一个简单的404。 –
该死的,我真的不明白为什么它是404,我已经直接从我知道的api复制代码。嗯,我会再试一次测试网址。 – Jimmyt1988