相关疑难解决方法(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万
查看次数

here-document给出'意外的文件结束'错误

我需要我的脚本从终端发送电子邮件.基于我在这里看到的以及许多其他地方的在线,我将它格式化为:

/var/mail -s "$SUBJECT" "$EMAIL" << EOF
Here's a line of my message!
And here's another line!
Last line of the message here!
EOF
Run Code Online (Sandbox Code Playgroud)

但是,当我运行这个时,我得到这个警告:

myfile.sh: line x: warning: here-document at line y delimited by end-of-file (wanted 'EOF')

myfile.sh: line x+1: syntax error: unexpected end of file
Run Code Online (Sandbox Code Playgroud)

...其中第x行是程序中最后写入的代码行,第y行是其中的行/var/mail.我试着更换EOF其他的事情(ENDOFMESSAGE,FINISH,等),但无济于事.我在网上找到的几乎所有内容都是这样做的,而且我真的很喜欢bash,所以我很难自己搞清楚.有人可以提供任何帮助吗?

email bash heredoc

64
推荐指数
3
解决办法
9万
查看次数

标签 统计

bash ×1

curl ×1

email ×1

heredoc ×1

http-headers ×1

json ×1

rest ×1

spring-mvc ×1