CloseableHttpClient httpclient = HttpClients.createDefault();
try {
String url = "URL";
JSONObject paramData = new JSONObject();
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("SHAREDB.STU_SCORE.KCH", "1");
paramData.put("params", paramData);
paramData.put("address", "DWH");
paramData.put("token", "授权码");
HttpPost httppost = new HttpPost(url);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("data", paramData.toString()));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params,
"UTF-8");
httppost.setEntity(entity);
CloseableHttpResponse response = httpclient.execute(httppost);
try {
System.out.println(response.getStatusLine());
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
resultData = EntityUtils
.toString(resEntity, "UTF-8");
System.out.println("***************************************");
System.out.println("resultData:"+resultData);
System.out.println("**********************************************");
}
EntityUtils.consume(resEntity);
} catch (Exception ex) {
ex.printStackTrace();
}
response.close();
} catch (Exception ex) {
ex.printStackTrace();
}
try {
httpclient.close();
} catch (Exception ex) {
}
JAVA访问网址获取JSON数据
最新推荐文章于 2024-07-26 03:19:09 发布