|
|
|
@ -50,7 +50,7 @@ public class HttpUtils {
|
|
|
|
|
* @param url
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String get(String url) {
|
|
|
|
|
public static String get(String url) throws Exception {
|
|
|
|
|
HttpGet httpGet = new HttpGet(url);
|
|
|
|
|
return getResult(httpGet);
|
|
|
|
|
}
|
|
|
|
@ -58,7 +58,7 @@ public class HttpUtils {
|
|
|
|
|
* @param url、params
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String get(String url, Map<String, String > params) throws URISyntaxException {
|
|
|
|
|
public static String get(String url, Map<String, String > params) throws Exception {
|
|
|
|
|
URIBuilder ub = new URIBuilder();
|
|
|
|
|
ub.setPath(url);
|
|
|
|
|
|
|
|
|
@ -73,7 +73,7 @@ public class HttpUtils {
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String get(String url, Map<String, Object> headers, Map<String, String> params)
|
|
|
|
|
throws URISyntaxException {
|
|
|
|
|
throws Exception {
|
|
|
|
|
URIBuilder ub = new URIBuilder();
|
|
|
|
|
ub.setPath(url);
|
|
|
|
|
|
|
|
|
@ -92,7 +92,7 @@ public class HttpUtils {
|
|
|
|
|
* @param url
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String post(String url) {
|
|
|
|
|
public static String post(String url) throws Exception {
|
|
|
|
|
HttpPost httpPost = new HttpPost(url);
|
|
|
|
|
return getResult(httpPost);
|
|
|
|
|
}
|
|
|
|
@ -100,7 +100,7 @@ public class HttpUtils {
|
|
|
|
|
* @param url、params
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String post(String url, Map<String, String> params) throws UnsupportedEncodingException {
|
|
|
|
|
public static String post(String url, Map<String, String> params) throws Exception {
|
|
|
|
|
HttpPost httpPost = new HttpPost(url);
|
|
|
|
|
httpPost.setEntity(new UrlEncodedFormEntity(covertParams2NVPS(params), "utf-8"));//设置表单提交编码
|
|
|
|
|
|
|
|
|
@ -108,7 +108,7 @@ public class HttpUtils {
|
|
|
|
|
return getResult(httpPost);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String post(String url, Object params, Map<String, Object> head) throws UnsupportedEncodingException {
|
|
|
|
|
public static String post(String url, Object params, Map<String, Object> head) throws Exception {
|
|
|
|
|
HttpPost httpPost = new HttpPost(url);
|
|
|
|
|
System.out.println(params);
|
|
|
|
|
httpPost.setEntity(new StringEntity(params.toString()));//设置表单提交编码
|
|
|
|
@ -136,7 +136,7 @@ public class HttpUtils {
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String post(String url, Map<String, Object> headers, Map<String, Object> params)
|
|
|
|
|
throws UnsupportedEncodingException {
|
|
|
|
|
throws Exception {
|
|
|
|
|
HttpPost httpPost = new HttpPost(url);
|
|
|
|
|
System.out.println(params);
|
|
|
|
|
if (params != null) {
|
|
|
|
@ -156,10 +156,10 @@ public class HttpUtils {
|
|
|
|
|
* @param request
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private static String getResult(HttpRequestBase request) {
|
|
|
|
|
private static String getResult(HttpRequestBase request) throws Exception{
|
|
|
|
|
// CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
|
|
CloseableHttpClient httpClient = getHttpClient();
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
CloseableHttpResponse response = httpClient.execute(request);
|
|
|
|
|
// response.getStatusLine().getStatusCode();
|
|
|
|
|
HttpEntity entity = response.getEntity();
|
|
|
|
@ -170,13 +170,7 @@ public class HttpUtils {
|
|
|
|
|
// httpClient.close();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
} catch (ClientProtocolException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return EMPTY_STR;
|
|
|
|
|
}
|
|
|
|
|