在我的程序中,我需要获取网站的内容,但是webclient对象的DownloadString方法的返回返回null,但是最吸引人的是没有例外。状态码为200,请求已完全发出,但url返回一个空字符串。
WebClient wc = new WebClient();
String teste = wc.DownloadString("http://www.wiplay.com.br");
好像您的网站需要设置用户代理标头才能响应。
在调用DownloadString方法之前添加以下内容:
wc.Headers.Add(HttpRequestHeader.UserAgent, "your useragent string");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句