给http post传参,参考以下二个实例:
//serverURL url地址
HttpPost httpPost = new HttpPost(serverURL);
//param 为参数
StringEntity entity = new StringEntity(param);
entity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(entity);
HttpResponse httpResponse = httpClient.execute(httpPost);
还可以用map作为参数
List
if(param!=null){
Set set = param.keySet();
Iterator iterator = set.iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
Object value = param.get(key);
formparams.add(new BasicNameValuePair(key.toString(), value.toString()));
}
}
用HttpKit.post方法,可以传参,不过是要以map的形式才行。例如:
String resp = HttpKit.post(URL, paramStr, headerMap);
List nameValuePairs = new ArrayList(2); nameValuePairs.add(new BasicNameValuePair("userid", "12312")); nameValuePairs.add(new BasicNameValuePair("sessionid", "234")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));