HttpPost + setEntity : how to know content-length? [duplicate]
-
21-12-2019 - |
Question
I've set almost all my data :
String capcha = editText.getText().toString();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("myurl.asp");
// Add your data
String str = "param1=x¶m2=y";
StringEntity strEntity = new StringEntity(str);
httppost.setEntity(strEntity);
httppost.setHeader("Set-Cookie", sessionCookie);
httppost.setHeader("Accept", "text/html");
httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");
// httppost.setHeader("Content-Length", ); HOW TO GET CONTENT LENGTH ?
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
Thanks for your help.
Solution
Perhaps this may help to solve your problem:
httppost.setHeader("Content-Length", String.valueOf(strEntity.getContentLength()));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow