JSON POST-Spring MVC Curl-400错误请求 这是我的curl方法请求映射到POJO,但失败为400:
卷曲请求:JSON POST-Spring MVC Curl-400错误请求 这是我的curl方法请求映射到POJO,但失败为400:,spring,spring-mvc,curl,Spring,Spring Mvc,Curl,卷曲请求: curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"key":"XYZ","uniqueId":"ABCD"}' http://localhost:8080/api/rest/connect/tick/view.json * Adding handle: conn: 0x1cb54c0 * Adding handle: send: 0 * Adding
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"key":"XYZ","uniqueId":"ABCD"}' http://localhost:8080/api/rest/connect/tick/view.json
* Adding handle: conn: 0x1cb54c0
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x1cb54c0) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 8080 (#0)
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /api/rest/connect/tick/view.json HTTP/1.1
> User-Agent: curl/7.32.0
> Host: localhost:8080
> Accept: application/json
> Content-type: application/json
> Content-Length: 53
>
* upload completely sent off: 53 out of 53 bytes
< HTTP/1.1 400 Bad Request
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Content-Type: text/html;charset=utf-8
< Content-Length: 971
< Date: Thu, 19 Sep 2013 13:16:29 GMT
< Connection: close
CONNECTSERVICEBEAN:
import java.io.Serializable;
public class ConnectServiceBean implements Serializable {
private static final long serialVersionUID = 1L;
private String key;
private String uniqueId;
//Getters and setters }
但正在为另一个方法工作,请求映射到字符串:
控制器:
@RequestMapping(value="/tick/{key}/view.*", method = RequestMethod.POST, consumes="application/json", produces = "application/json; charset=utf-8")
public IConnectResponse tickConnectPostString (
@PathVariable("key") String key, @RequestBody String uniqueId
) {}
我觉得Jackson映射有问题。但是我有所有必要的POM依赖项,我在其他一些stackoverflow文章中也读到过,其中我只需要针对bean映射的Jackson配置(尽管不确定)
org.codehaus.jackson
jackson core asl
1.9.7
org.codehaus.jackson 杰克逊地图绘制者 1.9.7
什么是products=MediaType.APPLICATION\u JSON\u值?products=“application/json;charset=utf-8”)应该可以工作。谢谢。我根据你的建议更改了它,但没有成功:(你是否试图在发送之前连接ServiceBean字符串化它?请发布ajax方法谢谢阿里,按照链接()我在spring mvc上打开了log4j跟踪,可以看到解析错误。这基本上是JSON输入格式不正确。所以做了一些尝试和错误,并更改了crul请求以使其工作。curl-v-H“Accept:application/JSON”-H“Content type:application/JSON”-X POST-d{“key\”:“XYZ\,“uniqueId\”:“ABCD\”}@Pradeep THIS{\“key\”:“XYZ\”,“uniqueId\”:“ABCD\”}谢谢!
import java.io.Serializable;
public class ConnectServiceBean implements Serializable {
private static final long serialVersionUID = 1L;
private String key;
private String uniqueId;
//Getters and setters }
curl -i -H "Content-Type: application/json" -X POST -d '{"JKL@user.com"}' http://localhost:8080/api/rest/connect/tick/XYZ/view.json
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Pragma: no-cache
Cache-Control: no-cache, no-store, max-age=0
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: application/json;charset=UTF-8
Content-Language: en-GB
Transfer-Encoding: chunked
Date: Thu, 19 Sep 2013 13:11:40 GMT
@RequestMapping(value="/tick/{key}/view.*", method = RequestMethod.POST, consumes="application/json", produces = "application/json; charset=utf-8")
public IConnectResponse tickConnectPostString (
@PathVariable("key") String key, @RequestBody String uniqueId
) {}