网页API的OData 2 = $不灵格式 [英] Web API 2 OData = $format not working

查看:150
本文介绍了网页API的OData 2 = $不灵格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在先进的感谢任何帮助球员。

Thanks in advanced for any help guys.

我有一个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

均无功而返。这篇文章说,这是可能的:<一href=\"http://blogs.msdn.com/b/webdev/archive/2014/03/13/getting-started-with-asp-net-web-api-2-2-for-odata-v4-0.aspx\" rel=\"nofollow\">http://blogs.msdn.com/b/webdev/archive/2014/03/13/getting-started-with-asp-net-web-api-2-2-for-odata-v4-0.aspx

我更新了所有我的NuGet包,但似乎该请求总是被忽略,而是我得到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.

有任何想法再次感谢。最亲切的问候......

Thanks again for any ideas. Kindest regards...

推荐答案

由于ATOM格式(XML)只是一个技术委员会规范,而不是为OData的V4协议OASIS标准,Atom格式在ODataLib从禁用 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

或设置页眉接受应用程序/原子+ XML 。但是由于上面提到的原因,它不会对网页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.

这篇关于网页API的OData 2 = $不灵格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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