2011-10-24 69 views
0

我知道如何在android中發送post請求。我使用下面的示例代碼:發送HttpPost請求時的HttpEntity概念

... 
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類背後有什麼想法?

回答

0

HTTPEntity doc:可以通過HTTP消息發送或接收的實體。實體可以在requestsresponses中找到,它們是可選的。