android-HttpPost setEntity:如何知道内容长度?
作者:互联网
这个问题已经在这里有了答案: > How to set content-length in android? 1个
我已经设置了几乎所有数据:
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);
谢谢你的帮助.
解决方法:
也许这可能有助于解决您的问题:
httppost.setHeader("Content-Length", String.valueOf(strEntity.getContentLength()));
标签:content-length,entity,http-post,android 来源: https://codeday.me/bug/20191030/1965959.html