接口最好还是请求方式定义为json格式比较好,
下面是简单名称值对节点类型NameValuePair 的post的请求方式,算是比较费事的
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("clientId", clientId));
params.add(new BasicNameValuePair("secret", secret));
httpPostToken.setEntity(new UrlEncodedFormEntity(params, "utf-8"));
String responseJsonToken = HttpUtil.postNameValuePair(httpPostToken);
/***
* @Author
* @Description post NameValuePair请求
* @Date 14:35 2020/9/25
* @Param [stringBuilder, params]
* @return java.lang.String
**/
public static String postNameValuePair(HttpPost httpPost) throws IOException {
CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = client.execute(httpPost);
HttpEntity entity = response.getEntity();
if (entity != null) {
String result = EntityUtils.toString(entity, "UTF-8");
return result;
}
return null;
}