Commit fbc9605e authored by KeYong's avatar KeYong

更新调试信息

parent b90dfc89
package com.yeejoin.equipmanage.common.utils;
import com.alibaba.fastjson.JSON;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
......@@ -70,12 +71,15 @@ public class HttpsGetAndPostUtil {
*
* @throws Exception
*/
public static String sendByHttp(Map<String, String> params, String url) {
public static String sendByHttp(Map<String, String> headerMap, Map<String, String> params, String url) {
try {
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-type", "application/json; charset=utf-8");
httpPost.setHeader("Accept", "application/json");
for (Map.Entry<String, String> entry : headerMap.entrySet()) {
httpPost.setHeader(entry.getKey(), entry.getValue());
}
// 设置参数
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
......@@ -91,6 +95,7 @@ public class HttpsGetAndPostUtil {
httpClient = HttpsGetAndPostUtil.createSSLClientDefault();
httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println("新方法返回结果=================" + JSON.toJSONString(httpEntity));
if (httpEntity != null) {
String jsObject = EntityUtils.toString(httpEntity, "UTF-8");
return jsObject;
......
......@@ -71,7 +71,12 @@ public class DcsUtil {
map.put("scope", scope);
map.put("client_id", clientId);
map.put("client_secret", clientSecret);
String content = HttpsGetAndPostUtil.sendByHttp(map, gettokenUrl);
String content;
if (isHttpsUrl(gettokenUrl)){
content = HttpsGetAndPostUtil.sendByHttp(headerMap, map, gettokenUrl);
} else {
content = HttpContentTypeUtil.doPostForm(gettokenUrl, map);
}
logger.info("header:" + JSON.toJSONString(headerMap) + "; body: " + JSON.toJSONString(map) + "; 调用获取token返回:" + content);
if (StringUtils.isNotBlank(content)) {
AppTokenVo appTokenVo = JSONObject.parseObject(content, AppTokenVo.class);
......@@ -84,4 +89,9 @@ public class DcsUtil {
logger.info("accessToken 是----------" + accessToken);
return accessToken;
}
public static boolean isHttpsUrl(String url) {
String regex = "^https://.*$";
return url.matches(regex);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment