`
superlxw1234
  • 浏览: 542418 次
  • 性别: Icon_minigender_1
  • 来自: 西安
博客专栏
Bd1c0a0c-379a-31a8-a3b1-e6401e2f1523
Hive入门
浏览量:43242
社区版块
存档分类
最新评论

HttpClient PostMethod 传递json

    博客分类:
  • java
 
阅读更多

记录下,备查。

 

/**
	 * 获取post请求响应
	 * @param url
	 * @param params
	 * @return
	 */
	public static String urlPostMethod(String url,String params) {
		HttpClient httpClient = new HttpClient();
		PostMethod method = new PostMethod(url);
		try {
			if(params != null && !params.trim().equals("")) {
				RequestEntity requestEntity = new StringRequestEntity(params,"text/xml","UTF-8");
				method.setRequestEntity(requestEntity);
			}
			method.releaseConnection();
			httpClient.executeMethod(method);
			String responses= method.getResponseBodyAsString();
			return responses;
		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

 

调用:

 

String getURL = "http://localhost:8080/pr/rest/aggregation/getAll";
String params = "{everyPageNum:22,currentPage:1}";
String s = DataAggregationUtil.urlPostMethod(getURL, params);

System.out.println(s);

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics