当浏览器中的相同 GET 请求显示 XML 响应时,为什么 HTTPClient 响应会生成 JSON 流?

发布于 2024-09-26 19:10:28 字数 141 浏览 0 评论 0原文

我第一次使用 HttpClient 向 Web 服务(由 WADL 定义)发出请求,如果我在浏览器中执行 Get 请求,它会使用 XML 进行响应,则我想将响应解编为有意义的对象。但是当我显示代码的响应时,它似乎是 JSON。我是不是少了一步?或者有没有办法可以转换?

I am using HttpClient for the first time to make a request to a web service (defined by WADL), I'd like to unmarshall the response into a meaningful object, in the browser if I perform the Get request it response with XML. But when I display the response from the code it seems to be JSON. Am I missing a step? or is there a way this can be converted?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最佳男配角 2024-10-03 19:10:28

浏览器和代码是否有可能发送不同的 Accept: 标头? http://www.w3.org/Protocols/rfc2616/rfc2616 -sec14.html#sec14.1

您可以尝试从代码中发送“application/xml,text/xml”的 Accept 标头,看看是否会发生变化?另一件要做的事情是使用 Firebug 等工具检查浏览器发送的标头,因为如果 URL 相同,则几乎可以肯定是正在发送的标头之一改变了行为。

Is it possible that the browser and the code are sending different Accept: headers? http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1

Can you try sending an Accept header of "application/xml, text/xml", say, from the code and see if that changes things? Another thing to do is to check the headers the browser is sending using a tool like Firebug, for example, because if the URL is the same, it's almost certainly one of the headers being sent that's changing the behaviour.

羅雙樹 2024-10-03 19:10:28

我猜测网络服务会根据用户代理或请求的其他不同内容返回不同的响应。检查所有参数是否相同。还要检查 HttpClient 是否执行 GET 而不是 POST。除非您的 Web 浏览器和 HttpClient 请求之间的参数或标头不同,否则响应中不应有任何差异。

I'm guessing the webservice is returning a different response depending on the user-agent or something else different about the request. Check all teh parameters are identical. Also check the HttpClient is doing a GET not a POST. There should be no difference in the response unless parameters or headers differ between your web-browser and your HttpClient request.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文