Web API 2 OData = $ format不起作用:始终忽略该请求 [英] Web API 2 OData = $format not working: the request is always ignored

查看:57
本文介绍了Web API 2 OData = $ format不起作用:始终忽略该请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web API OData项目,并且一切正常.我现在正在尝试使用$ format参数而不是指定标头请求来返回xml而不是JSON,并且它不起作用.我已经尝试过以下方法:

I have a Web API OData project and everything is working great. I'm now trying to return xml instead of JSON using the $format parameter, as opposed to specifying a header request, and it is not working. I've tried these approaches:

http://localhost:3845/api/Customer?$format=application/xml
http://localhost:3845/api/Customer?$format=xml
http://localhost:3845/api/Customer?$format=application/xml;odata.metadata=full

一切都没有成功.本文说有可能:

All without success. This article says that it is possible: https://blogs.msdn.microsoft.com/webdev/2014/03/13/getting-started-with-asp-net-web-api-2-2-for-odata-v4-0/

我已经更新了所有的Nu​​Get软件包,但是似乎总是忽略了该请求,而是每次都获取JSON.

I have updated all of my NuGet packages, but it seems that the request is always ignored, and instead I get JSON every time.

推荐答案

由于ATOM格式(XML)只是一个技术委员会规范,而不是OData V4协议的OASIS标准,因此从以下版本的ODataLib中禁用了ATOM格式: 版本6.3.0 .

Since the ATOM format (XML) is only a technical committee specification instead of an OASIS standard for the OData V4 protocol, the ATOM format is disabled in the ODataLib from the version 6.3.0.

要求OData V4服务以XML响应的正确方法如下:

The correct way to ask the OData V4 service to respond in XML is as follows:

GET http://localhost:3845/api/Customer?$format=application/atom+xml

或将标题Accept设置为application/atom+xml.但是由于上述原因,它不适用于Web API OData V4.

or set the header Accept to application/atom+xml. But due to the reason mentioned above, it doesn't work for Web API OData V4.

这篇关于Web API 2 OData = $ format不起作用:始终忽略该请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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