httpClient类
@SuppressWarnings("finally")
public JSONObject doPost(String url, String parms){
if ("".equals(url))
return null;
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
StringBuffer json = new StringBuffer();
JSONObject response = null;
String line = null;
try {
post.setEntity(new StringEntity(parms, "UTF-8"));
HttpResponse res = client.execute(post);
HttpEntity entity = res.getEntity();
InputStream instream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(instream, "GBK"));
while((line = reader.readLine()) != null) {
json.append(line);
}
String content = java.net.URLDecoder.decode(json.toString(), "GBK");
response = new JSONObject(content);
} catch (Exception e) {
e.printStackTrace();
} finally{
System.out.println("请求参数:"+parms.toString());
System.out.println("响应参数:"+response.toString());
return response;
}
}