Я пытаюсь отправить JSON в службу отдыха, используя Apache Httpclient. Тем не менее, я получаю эту ошибку:
Exception in thread "main" org.apache.http.ProtocolException: Content-Length header already present
UsernamePasswordCredentials defaultcreds = new UsernamePasswordCredentials(USER,
PASS);
HttpHost targetHost = new HttpHost("localhost", 8080, "http");
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()),
new UsernamePasswordCredentials(USER, PASS));
HttpPost httpPost = new HttpPost(urlSuffix) {};
JSONObject holder = new JSONObject();
holder.put("name", "this is a folder");
StringEntity se = new StringEntity(holder.toString());
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
httpPost.setEntity(se);
HttpResponse resp = httpclient.execute(targetHost,httpPost);
System.out.println("Resp->" + resp.getStatusLine().getStatusCode());
Я прочитал его, потому что уже дважды задаю длину контента, но не уверен, как это исправить.