不多逼逼,直接上代码(其实我也有点懵逼)
httpRequst.setEntity()这个方法是最主要的post传递的参数实现的方式
try{
HttpPost httpPost = new HttpPost(url);
StringEntity stringEntity = new StringEntity(param);//param参数,可以为"key1=value1&key2=value2"的一串字符串
stringEntity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(stringEntity);
HttpClient client = new DefaultHttpClient();
HttpResponse httpResponse = client.execute(httpPost);
String result = EntityUtils.toString(httpResponse.getEntity(), HTTP.UTF_8);
} catch(IOException e){
}
List<NameValuePair>list = new ArrayList<NameValuePair>();
for (int i = 0; i < keys.length; i++) {
list.add(new BasicNameValuePair(keys[i], values[i]));
}
HttpPost httpRequst = new HttpPost(urlString);
httpRequst.setEntity(new UrlEncodedFormEntity(list,HTTP.UTF_8));