HttpClient------post
HttpClient httpClient = new HttpClient(); PostMethod postMethod = new PostMethod("http:***");//send url
NameValuePair[] datas = {new NameValuePair("aaaaa", aaaa), new NameValuePair("bbbb", bbbb), new NameValuePair("cccc", ccccc)};postMethod.setRequestBody(datas);
httpClient.executeMethod(postMethod);byte[] responseByte = postMethod.getResponseBody(); String responseBody = new String(responseByte, "UTF-8");//解析responseBody装换成MapMap<String, String> jsonMap = JSON.parseObject(responseBody, new TypeReference<TreeMap<String, String>>() {});HttpClient------getHttpClient httpClient = new HttpClient(); GetMethod getMethod = new GetMethod(url);int statusCode = httpClient.executeMethod(getMethod); if(statusCode != 200) { customError = "Get request failed, response code = " + statusCode; } InputStream responseStream = getMethod.getResponseBodyAsStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(responseStream, "UTF-8")); String line = reader.readLine(); if(line.startsWith("{")) { Map<String, Object> jsonMap = JSON.parseObject(line, TreeMap.class);}Note:JSON.parseObject
package com.alibaba.fastjson;
通过java.net.URLConnection发送HTTP请求的方法
http://www.cnblogs.com/nick-huang/p/3859353.html