Apache Httpclient를 사용하여 일부 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());
이미 두 번 콘텐츠 길이를 설정하고 있습니다 때문에 나는 그것을 읽었습니다,하지만 난 그것을 해결하는 방법을 모르겠어요.
이 방법은 현재 사용되지 않습니다. – voondo