首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何根据请求头将ResponseFormat从XML更改为JSON

如何根据请求头将ResponseFormat从XML更改为JSON
EN

Stack Overflow用户
提问于 2016-01-15 19:40:04
回答 1查看 75关注 0票数 0

我有一个用vb.net编写的REST Service,默认情况下,除非我设置了ResponseFormat:=WebMessageFormat.Json,否则返回的响应是XML。所以我希望我可以根据用户传入的头来更改ResponseFormat。所以我会这样编写我的<WebGet>代码:

代码语言:javascript
复制
<WebGet(UriTemplate:="UserNames/", BodyStyle:=WebMessageBodyStyle.WrappedResponse)>
Public Function UserNamesList() As List(Of UserNames)

    'check the Headers for either XML or Json and then set the ResponseFormat
    Return intUserNamesList()

End Function

那么,有没有办法在<WebGet>声明之外设置ResponseFormat或等效物呢?

EN

回答 1

Stack Overflow用户

发布于 2016-01-15 19:49:42

我想我已经破解了。我可以在我的函数中使用WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.XmlWebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34810262

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档