사용자 로그인을위한 게시물 요청을 만들어야합니다. 나는 콘텐츠 길이 헤더를 설정하고하지만 난 요청을 게시 할 때 org.apache.http.client.HttpResponseException 제공 : 필수 길이를android - http post content-length (json post)
난 콘텐츠 길이 헤더를 설정
DefaultHttpClient httpclient = new DefaultHttpClient();
JSONObject data = new JSONObject();
data.put("UserName", username);
data.put("Password", password);
data.put("RememberMe", false);
HttpPost httpost = new HttpPost(LOGIN_PATH);
StringEntity se = new StringEntity(data.toString());
httpost.setEntity(se);
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-Type", "application/json");
httpost.setHeader("Content-Length",""+se.getContentLength());
ResponseHandler responseHandler = new BasicResponseHandler();
return httpclient.execute(httpost, responseHandler);
내 코드는 준다 'Content-Length header already present'이고, content-lenght header를 제거하면 'Length is required'가됩니다.
고마워요.
에 열쇠로
Content-Length
대신Content-Lenght
(길이 맞춤법 실수)를 통과하기 때문에에 . 감사합니다 – dracula