我正在尝试使用网络API来下载页面。 指向api的链接:http://api.arbetsformedlingen.se/
如果我使用以下代码:
HttpClient c = new HttpClient();
c.BaseAddress = new Uri("http://api.arbetsformedlingen.se/");
var response = c.GetAsync("platsannons/soklista/kommuner?lanid=10").Result;
请求如下:
{Method: GET, RequestUri: 'http://api.arbetsformedlingen.se/platsannons/soklista/kommuner?lanid=10', Version: 1.1, Content: <null>, Headers:{}}
这不足以获得有效的回复吗?我得到的是400 Bad请求:
StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:{ Connection: close Proxy-Connection: keep-alive Date: Fri, 28 Jun 2013 10:02:34 GMT Server: Apache Content-Length: 117 Content-Type: application/json; charset=UTF-8}
我是否需要在内容中包含某些内容?
答案 0 :(得分:2)
这不足以获得有效的回复吗?
这完全取决于服务器。尝试将您的请求与从浏览器发出的“真实”请求进行比较,例如使用Fiddler,并发现差异。服务器可能会通过返回400
来阻止自动请求。