Android HttpPost&x2B;setEntity:如何知道内容长度?

Android HttpPost&x2B;setEntity:如何知道内容长度?,android,entity,http-post,content-length,Android,Entity,Http Post,Content Length,我已经设置了几乎所有的数据: 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 str

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

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);

谢谢您的帮助。

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

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

@Waqas链接的问题是指我没有使用的
HttpUrlConnection
。我怎样才能做到?