如何使用 GET 请求将对象传递给 RESTful 服务? [英] How to pass object to RESTful Service with GET request?

查看:31
本文介绍了如何使用 GET 请求将对象传递给 RESTful 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 stackoverflow 中看到一些帖子说发送项目列表在 GET 方法中,是不允许的.它只能通过 POST 方法完成"

I have seen some posts in stackoverflow saying "sending list of items in the GET Method, is NOT allowed. It has to be accomplished via POST method only"

我的代码看起来像

    [OperationContract]
    [WebGet(UriTemplate = "Employee/{emp}",RequestFormat=WebMessageFormat.Json)]
    Employee GetEmpDetails(string emp);

我的输入 json 对象将是 "{'id':1,'name':'test',....}有没有其他方法可以解决这个问题.

and my input json object will be "{'id':1,'name':'test',....} Is there any alternative way of achieving this issue.

谢谢

推荐答案

可以使用 GET 发送项目列表,只是开箱即用,仅支持原始值.字符串值工作得很好,但如果你想传递一个复杂的对象,你需要创建一个自定义的QueryStringConverter.http://blogs 上的帖子.msdn.com/b/carlosfigueira/archive/2011/08/09/wcf-extensibility-querystringconverter.aspx 解释了如何做到这一点.

It is possible to send list of items with GET, it's just that out of the box only primitive values are supported. String values work just fine, but if you want to pass a complex object, you need to create a custom QueryStringConverter. The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/08/09/wcf-extensibility-querystringconverter.aspx explains how this can be done.

这篇关于如何使用 GET 请求将对象传递给 RESTful 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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