简体   繁体   中英

C# code to retrieve xml data

Based on the this sourcecode I'm not able to retrieve the data from the API into XDocument .

I retrieve the error message

{"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"));

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"));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM