Я использую RESTfull WebService с помощью этого метода:Как передать объект как параметры с HttpPost
@RequestMapping(value = "/rest/secure/Userprofile/{providerId}", method = RequestMethod.POST)
@ResponseBody
public List<Userprofile> addUserprofile(@RequestBody Object[] socialAccounts, @PathVariable String providerId, HttpServletRequest request, HttpServletResponse response) {
System.out.println("do something!!!");
}
Я хочу передать socialAccount объект.
String json = "{\"id\":\"26651480000\",\"selected\":true,\"category\":\"Software\",\"perms\":[\"ADMINISTER\",\"EDIT_PROFILE\",\"CREATE_CONTENT\",\"MODERATE_CONTENT\",\"CREATE_ADS\",\"BASIC_ADMIN\"],\"provideruserid\":\"1475334273\",\"name\":\"Eran\",\"useraccesstoken\":\"CAABletmsJHgBANXAhAlaQXVN1TrI5Tq8gvU002Ke8ZB2dcAhoo21u8orrHiT77G3cm6CmJ4zBX2mu8koeq\",\"checked\":false,\"access_token\":\"CAAB0000wcuq8O\"}";
CloseableHttpClient httpclient = HttpClients.createDefault();
URIBuilder builder = new URIBuilder();
builder.setScheme("http").setHost("localhost:8080/AppDev")
.setPath("/rest/secure/Userprofile/facebook/");
URI uri = builder.build();
HttpPost httppost = new HttpPost(uri);
ArrayList<NameValuePair> postParameters;
postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("socialAccounts", json));
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
httppost.setHeader("X-Auth-Token", userLogged.getToken());
httppost.addHeader("Content-Type", "application/json;charset=UTF-8");
CloseableHttpResponse response = httpclient.execute(httppost);
Я получаю это: HTTP/1.1 400 Bad Request
Некоторые советы?
Вы должны указать 'заголовок Content-type' поэтому конечная точка будет знать, как декодировать содержимое запрос в (я не думаю, что это ответ, хотя, только наконечник) –