相关疑难解决方法(0)

如何使用Curl从终端/命令行发布JSON数据到测试Spring REST?

我使用Ubuntu并在其上安装了Curl.我想用Curl测试我的Spring REST应用程序.我在Java端编写了我的POST代码.但是,我想用Curl测试它.我正在尝试发布JSON数据.示例数据如下:

{"value":"30","type":"Tip 3","targetModule":"Target 3","configurationGroup":null,"name":"Configuration Deneme 3","description":null,"identity":"Configuration Deneme 3","version":0,"systemId":3,"active":true}
Run Code Online (Sandbox Code Playgroud)

我用这个命令:

curl -i \
    -H "Accept: application/json" \
    -H "X-HTTP-Method-Override: PUT" \
    -X POST -d "value":"30","type":"Tip 3","targetModule":"Target 3","configurationGroup":null,"name":"Configuration Deneme 3","description":null,"identity":"Configuration Deneme 3","version":0,"systemId":3,"active":true \
    http://localhost:8080/xx/xxx/xxxx
Run Code Online (Sandbox Code Playgroud)

它返回此错误:

HTTP/1.1 415 Unsupported Media Type
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Length: 1051
Date: Wed, 24 Aug 2011 08:50:17 GMT
Run Code Online (Sandbox Code Playgroud)

错误描述如下:

服务器拒绝此请求,因为请求实体的格式不受所请求方法()的请求资源支持.

Tomcat日志:"POST/ui/webapp/conf/clear HTTP/1.1"415 1051

关于Curl命令的正确格式的任何想法?

编辑:

这是我的Java端PUT代码(我测试过GET和DELETE,它们有效)

@RequestMapping(method = RequestMethod.PUT)
public Configuration updateConfiguration(HttpServletResponse response, @RequestBody Configuration configuration) { //consider @Valid tag
    configuration.setName("PUT worked");
    //todo If error occurs …
Run Code Online (Sandbox Code Playgroud)

rest json curl spring-mvc http-headers

2606
推荐指数
24
解决办法
263万
查看次数

如何在Flask中获得POST的json?

我正在尝试使用Flask构建一个简单的API,我现在想要阅读一些POSTed JSON.我使用PostMan Chrome扩展程序发布帖子,而JSON我的帖子很简单{"text":"lalala"}.我尝试使用以下方法读取JSON:

@app.route('/api/add_message/<uuid>', methods=['GET', 'POST'])
def add_message(uuid):
    content = request.json
    print content
    return uuid
Run Code Online (Sandbox Code Playgroud)

在浏览器上它正确地返回我放入GET的uuid,但是在控制台上,它只是打印出来None(我希望它打印出来{"text":"lalala"}.有人知道我如何从Flask方法中获取发布的JSON吗?

python post json flask

284
推荐指数
8
解决办法
37万
查看次数

标签 统计

json ×2

curl ×1

flask ×1

http-headers ×1

post ×1

python ×1

rest ×1

spring-mvc ×1