我正在尝试使用webclient下载网页并获取500内部错误
public class AsyncWebClient { public string GetContent(string url) { return GetWebContent(url).Result.ToString(); } private Task<string> GetWebContent(string url) { var wc = new WebClient(); TaskCompletionSource<string> tcs = new TaskCompletionSource<string>(); wc.DownloadStringCompleted += (obj,args) => { if (args.Cancelled == true) { tcs.TrySetCanceled(); return; } if (!String.IsNullOrEmpty(args.Result)) tcs.TrySetResult(args.Result); }; wc.DownloadStringAsync(new Uri(url)); return tcs.Task; } }
并致电:
var wc =new AsyncWebClient(); var html = wc.GetContent("http://truyen.vnsharing.net/"); >> always get the above error
如果我使用其他网站,那么它的工作正常.不知道这个网站有什么特别之处.
请帮忙 !!