【问题标题】:HttpPost + setEntity : how to know content-length? [duplicate]HttpPost + setEntity:如何知道内容长度? [复制]
【发布时间】:2013-11-17 23:40:16
【问题描述】:

我已经设置了几乎所有的数据:

String capcha = editText.getText().toString();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("myurl.asp");

// Add your data                    
String str = "param1=x&param2=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);

感谢您的帮助。

【问题讨论】:

  • @Waqas 链接的问题是指我没有使用的HttpUrlConnection。我该怎么做?

标签: android entity http-post content-length


【解决方案1】:

也许这可能有助于解决您的问题:

httppost.setHeader("Content-Length", String.valueOf(strEntity.getContentLength()));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 2019-11-11
    • 2012-10-06
    • 1970-01-01
    相关资源
    最近更新 更多