如何用curl发布到REST / JSON服务? [英] how to post with curl to REST/JSON service?

查看:158
本文介绍了如何用curl发布到REST / JSON服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在

http://www.javacodegeeks.com/2013/04/spring-mvc-easy-rest-based-json-services -with-responsebody.html

,JQuery客户端可以成功地将一个人对象发布到服务! Yahoo!

and the JQuery client can successfully post a person object to the service! Yahoo!

如何使用cURL做同样的事情?
这是我的尝试:

How do I do the same thing with cURL? Here is my attempt:

curl -i -X POST -H "Content-Type: application/json; charset=UTF-8" -H "Accept: application/json" -d "{'name':'siegfried','age':26}" http://localhost:8080/api/person
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    71  100    42  100    29     39     26  0:00:01  0:00:01 --:--:--    40
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: 42
Server: Jetty(6.1.25)

Saved person: Person [name=null, age=null]
Compilation finished at Sun Dec 08 22:14:05

它不是解析数据!我如何让它解析我的json数据?

It is not parsing the data! How do I make it parse my json data?

我一直在谷歌搜索小时,尝试许多组合的转义报价和撇号等,没有什么似乎工作

I've been google searching for hours and trying out many combinations of escaping quotes and apostrophes and the like and nothing seems to work.

感谢

siegfried

siegfried

推荐答案

-d 会将您的数据作为发布发送,您不需要声明 POST

The -d will send your data as a post, you do not need to declare POST.

男人卷曲 介绍如何使用 -d 。如果任何人都需要它。

man curl gives the description on how to use -d. If anyone else would need it.

一个简单的Sinatra服务器 http://www.sinatrarb.com 或类似的东西,可以用来调试你的curls以及一个模拟服务器

A simple Sinatra server http://www.sinatrarb.com, or something like it, can be used to debug your curls as well as a mock server

有可能是问题是在服务器端,如果你在本地主机上运行它,你应该可以访问它,对吧?

Is there a possibility that the problem is on the server-side, if you run it on local host you should have access to it, right?

这篇关于如何用curl发布到REST / JSON服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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