httpClient使用方法
StringBuffer sb = new StringBuffer();
DefaultHttpClient httpclient = new DefaultHttpClient();
BufferedReader reader = null;
try{
if( urlString.lastIndexOf("?") > 1 ){
urlString = urlString + getRequestPram( parm, readCharset);
}else{
urlString = urlString + "?" + getRequestPram( parm, readCharset);
}
HttpGet httpGet = new HttpGet(urlString);
httpGet.addHeader("Content-Type","application/x-www-form-urlencoded; charset=\""+readCharset+"\"");
URI url = new URI(urlString);
// 设置请求的数据
httpGet.setURI(url);
// 执行
HttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
// 显示结果
reader = new BufferedReader(new InputStreamReader(entity.getContent(), "utf-8"));
String line = reader.readLine();
while (line != null) {
sb.append(line);
line = reader.readLine();
}
if (entity != null) {
entity.consumeContent();
}
}catch (Exception e) {
log.error("支付回调异常",e);
}finally{
try {
if(reader != null){
reader.close();
}
} catch (IOException e) {
log.error("",e);
}
httpclient.getConnectionManager().shutdown();
}
return sb.toString();
}