检索xml数据的C#代码 [英] C# code to retrieve xml data
本文介绍了检索xml数据的C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Based on the this sourcecode I'm not able to retrieve the data from the API into XDocument
.
我检索到错误信息
{"远程服务器返回错误:(400) 错误请求."}
{"The remote server returned an error: (400) Bad Request."}
问题:
我不知道该怎么办?
Question:
I don't know what to do?
XDocument xml = XDocument.Parse(new
WebClient().DownloadString("http://api.arbetsformedlingen.se/af/v0/platsannonser/matchning?lanid=1&kommunid=180&yrkesid=2419&1&antalrader=10000"));
推荐答案
您需要发送 HTTP 标头:
You need to send HTTP headers:
using (WebClient client = new WebClient())
{
client.Headers.Add("Accept-Language", " en-US");
client.Headers.Add("Accept", "application/xml");
client.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
XDocument xml = XDocument.Parse(client.DownloadString("http://api.arbetsformedlingen.se/af/v0/platsannonser/matchning?lanid=1&kommunid=180&yrkesid=2419&1&antalrader=10000"));
}
这篇关于检索xml数据的C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文