发送HttpPost请求时的HttpEntity概念

时间:2011-10-24 10:48:46

标签: android entity http-post

我知道如何在android中发送帖子请求。我使用以下示例代码:

...
HttpPost httpPostRequest = new HttpPost(url);
private  ArrayList <NameValuePair> params = new ArrayList<NameValuePair>();
private  ArrayList <NameValuePair> headers = new ArrayList<NameValuePair>();
.....
for(int i = 0; i < headers.size(); i++) {
    StringEntity entity = new StringEntity(headers.get(i).getValue(),"UTF-8");
    httpPostRequest.setEntity(entity);
}
if(!params.isEmpty()){
    HttpEntity httpEntity = new UrlEncodedFormEntity(params,HTTP.UTF_8);
    httpPostRequest.setEntity(httpEntity);
}

String serverResponse = executeRequest(httpPostRequest);
...

我只是想知道HttpEntity的概念是什么? HttpEntity课背后的想法是什么?

1 个答案:

答案 0 :(得分:0)

来自HTTPEntity doc:可以使用HTTP消息发送或接收的实体。可以在某些requestsresponses中找到实体,它们是可选的。