cURL JSON + Cookies + Header Params + Jersey

时间:2013-07-02 18:07:28

标签: java http cookies curl jersey

我正在尝试发送请求,我在curl中执行以下操作:

curl -v --header "location: 60.004:8.456" --cookie "sessionToken=~session" -i -X PUT -H 'Content-Type: application/json' -d '{"data":"{"FCT":"Welcome", "Uni":"Welcome to DI"}"}' localhost:8080/tester/apps/e39/data

由于某种原因它匹配类但没有这个方法:

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createDocumentRoot(JSONObject inputJsonObj,
        @Context UriInfo ui, @Context HttpHeaders hh) {
}

编辑: 该类使用@Path(“{appId} / data”)

定义

问题不在于路径,因为我已经对它进行了调试,并且看到它正确地识别了类,它只是在进入类之后抛出了错误的请求而没有输入任何方法。

这是curl verbose:

* About to connect() to localhost port 8080 (#0)
*   Trying 127.0.0.1... connected
> PUT /tester/apps/e39/data HTTP/1.1
> User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4                         libidn/1.23 librtmp/2.3
> Host: localhost:8080
> Accept: */*
> Cookie: sessionToken=~session
> location: 60.004:8.456
> Content-Type: application/json
> Content-Length: 60
> 
* upload completely sent off: 60out of 60 bytes
< HTTP/1.1 400 Bad Request
HTTP/1.1 400 Bad Request
< Server: Apache-Coyote/1.1
Server: Apache-Coyote/1.1
< Content-Type: text/html;charset=utf-8
Content-Type: text/html;charset=utf-8
< Content-Length: 990
Content-Length: 990
< Date: Tue, 02 Jul 2013 21:46:56 GMT
Date: Tue, 02 Jul 2013 21:46:56 GMT
< Connection: close
Connection: close

1 个答案:

答案 0 :(得分:0)

问题在于json语法不正确,我有

'{"data":"{"FCT":"Welcome", "Uni":"Welcome to DI"}"}'

更改为此后,它运行良好:

'{"data":
{"FCT":"Welcome",
"Uni":"Welcome to DI"}}'

我使用JSON在线解析器来检查json语法,这里是某人需要它的链接: http://json.parser.online.fr/