我有一些問題與發送請求到Spring MVC的控制器。 我有實體: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
不可以。只有鍵/值的雙引號 –