WebClient请求返回空字符串

Tuy*_*ius 7 .net c# webclient

在我的程序中,我需要获取我的站点的内容,但是webclient对象的DownloadString方法的返回返回null,但最有趣的是没有异常.状态代码为200,请求完美,但url返回一个空字符串.

WebClient wc = new WebClient();
String teste = wc.DownloadString("http://www.wiplay.com.br");
Run Code Online (Sandbox Code Playgroud)

我的网站 http://www.wiplay.com.br

coo*_*ine 5

似乎您的网站要求设置用户代理标头才能响应。

在调用DownloadString方法之前添加以下内容:

wc.Headers.Add(HttpRequestHeader.UserAgent, "your useragent string");
Run Code Online (Sandbox Code Playgroud)