带有 C# 代码的 XML 和 API 中的错误消息 [英] Error message in XML and API with C# Code

查看:19
本文介绍了带有 C# 代码的 XML 和 API 中的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于以下来自之前支持的代码::>

Based on this code below from previous support:

 using (WebClient client = new WebClient())
 {
     client.Headers.Add("Accept-Language", " en-US");
     client.Headers.Add("Accept", " text/html, application/xhtml+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"));
 }

我检索到错误消息

{System.Xml.XmlException} {"根级别的数据无效.第 1 行,位置 1."}

{System.Xml.XmlException} {"Data at the root level is invalid. Line 1, position 1."}

我尝试解决它,但找不到解决方案.

I tried solving it but I cannot find a solution to it.

推荐答案

您实际上得到的是一个 json,请更改以下内容:

You're actually getting a json, change the following:

client.Headers.Add("Accept", " text/html, application/xhtml+xml, */*");

client.Headers.Add("Accept", "application/xml");

这篇关于带有 C# 代码的 XML 和 API 中的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆