質問

In my program I need to get the content of my site, however the return of DownloadString method of the webclient object returns null, however the most intriguing is that there is no exception. the status code is 200, the request is made ​​perfectly, but the url returns an empty string.

WebClient wc = new WebClient();
String teste = wc.DownloadString("http://www.wiplay.com.br");

My site http://www.wiplay.com.br

役に立ちましたか?

解決

Seems like your website requires the user agent header to be set in order to respond.

Add the following before your call the DownloadString method:

wc.Headers.Add(HttpRequestHeader.UserAgent, "your useragent string");

他のヒント

In my case use of HttpClient and WebClient resulted in empty string despite status code 200 no matter what headers I set. If somebody still suffers to this problem,using RestSharp like finally returned expected response body.

var dataString = JObject.FromObject(anonymousObject).ToString();
var client = new RestClient(url);
var request = new RestRequest(Method.POST);
request.AddParameter("application/json", dataString, ParameterType.RequestBody);

var response = client.Post(request);

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top