cURL POST到rest端点导致服务器出错

时间:2015-09-20 14:35:55

标签: rest post curl jersey-2.0

我正在尝试向本地运行的rest端点发出POST请求,如下所示:

curl -X POST -d '[{"name":"xyz","cost":"10"}]' http://localhost:8080/xyz/rest/abc --header "Content-Type: application/json"

这导致

Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@3180b68d; line: 1, column: 2]

当我使用其他工具时,例如。 Firefox浏览器中的 RESTClient 插件我从我的休息端点获得了对此帖子正文的预期响应。

我在Jersey rest端点启用了请求的服务器端日志记录: RESTClient 请求导致:

15:48:31,916 INFO  [org.glassfish.jersey.filter.LoggingFilter] (http--127.0.0.1-
8080-1) 1 * Server has received a request on thread http--127.0.0.1-8080-1
1 > POST http://localhost:8080/xyz/rest/abc
1 > accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
1 > accept-encoding: gzip, deflate
1 > accept-language: null
1 > cache-control: no-cache
1 > connection: keep-alive
1 > content-length: 91
1 > content-type: application/json; charset=UTF-8
1 > host: localhost:8080
1 > pragma: no-cache
1 > user-agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Fire
fox/40.0

15:48:32,086 INFO  [org.glassfish.jersey.filter.LoggingFilter] (http--127.0.0.1-
8080-1) 1 * Server responded with a response on thread http--127.0.0.1-8080-1
1 < 201
1 < Content-Type: application/json

cURL请求导致:

15:49:04,786 INFO  [org.glassfish.jersey.filter.LoggingFilter] (http--127.0.0.1-
8080-2) 2 * Server has received a request on thread http--127.0.0.1-8080-2
2 > POST http://localhost:8080/xyz/rest/abc
2 > accept: application/json
2 > content-length: 76
2 > content-type: application/json
2 > host: localhost:8080
2 > user-agent: curl/7.33.0

15:49:04,792 INFO  [org.glassfish.jersey.filter.LoggingFilter] (http--127.0.0.1-
8080-2) 2 * Server responded with a response on thread http--127.0.0.1-8080-2
2 < 400
2 < Content-Type: text/plain

现在,我知道我的休息端点工作正常,只是好奇为什么cURL请求发生这种情况。欢迎任何建议。

0 个答案:

没有答案