【发布时间】:2012-11-19 08:06:40
【问题描述】:
我正在使用 curl 向 web 服务 http://localhost 2325//Service 发送 POST 请求
如何将 POST 请求的主体反序列化为一个变量,然后我可以在我的 POST 方法中访问该变量?
谁能给我一个例子?
这是我的方法
[WebInvoke(RequestFormat = WebMessageFormat.Json, UriTemplate = "/user", Method = "POST")] public void Create(User us)
类用户包含user_id 和user_name.
有人可以帮忙吗? 我需要的只是一个如何在 curl 中制定 POST 请求的示例
我试过了,但是不行
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"user":{"user_name":"Name1","user:id":"11"}}' http://localhost :3000/api/1/users
【问题讨论】:
-
不清楚这个问题与
curl有何关系。你能进一步扩展吗? -
您是否以想要反序列化的 json 格式发送它
-
是的,我发送的是 json 格式。我已经有一个类用户(来自数据库)
-
为什么在 C# 中使用 curl?您意识到 .NET 中内置了多种方法来满足这一需求,对吗?
-
因为 curl 是手动测试这类服务的好方法,无需编写 C# 客户端类。