// url 是你的请求名称
// paramsMap 是参数名称=参数值
public static String httpRequest(String url, Map paramsMp) throws UnsupportedEncodingException {
String resData = null;
//先将参数放入List,再对参数进行URL编码
List params = new LinkedList();
if (paramsMp != null) {
Set> entryset = paramsMp.entrySet();
for (Map.Entry entry : entryset) {
params.add(new BasicNameValuePair(entry.getKey(), URLEncoder.encode(entry.getValue(), "UTF-8")));
}
}
//对参数编码
String param = URLEncodedUtils.format(params, "UTF-8");
//将URL与参数拼接
HttpGet getMethod = new HttpGet(url+ "?" + param);
// 创建Client
HttpClient httpClient = new DefaultHttpClient();
// 执行get请求并得到返回结果
HttpResponse response;
try {
response = httpClient.execute(getMethod);
// 请求结束,返回结果
resData = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
return resData;
}