spring mvc 컨트롤러에 요청을 보내는 데 문제가 있습니다. 내가 가지고 기업 :SpringMVC 400 JSON 데이터 요청이 잘못되었습니다.
public class Person {
private String name;
private int age;
private String city;
//..getters setters
}
및 SpringMvc 컨트롤러 :
@Controller
@RequestMapping("/companies")
public class FirmaController {
@RequestMapping(value = "/addPerson", method = RequestMethod.POST, headers = {"Content-type=application/json"})
public String addPerson(@RequestBody Person person) {
return "person";
}
}
내가 컬와 서버에 요청을 전송하고자 할 때 : 내가 가지고
curl -i -X POST -HContent-Type:application/json -HAccept:application/json http://localhost:8080/api/companies/addPerson -d "{ 'name': 'Gerry', 'age': 20, 'city': 'Sydney' }"
HTTP/1.1 400 불량 요청 :
HTTP/1.1 400 Bad Request
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1392
Server: Jetty(8.1.10.v20130312)
내가 뭘 잘못 했니?
JSON 데이터의 키 값 쌍에 큰 따옴표를 추가 한 것을 볼 수 있습니다. – Chaitanya
아니요 키/값에 큰 따옴표 만 사용하십시오. –