发送给SAP的中间件的header参数放到请求头里

This commit is contained in:
彭枝刚 2024-12-17 10:23:53 +08:00
parent fe0b944949
commit 3b845254b6

View File

@ -26,13 +26,8 @@ public class SapUtil {
private static final String sapUser = "RFC";
private static final String sapPassword = "Admin@1234567890";
private static final JSONObject headJson;
static {
headJson = new JSONObject();
headJson.put("x-esb-apikey","hWS3L96a0h4NKCAjN9hG1OmOeEIsxCTz");
headJson.put("x-esb-env","DEV");
}
private static final String apikey = "hWS3L96a0h4NKCAjN9hG1OmOeEIsxCTz";
private static final String env = "DEV";
public static String appendHead(String jsonStr) {
@ -41,7 +36,6 @@ public class SapUtil {
JSONObject json = JSONObject.parseObject(jsonStr);
allJson.put("API_DATA", json);
allJson.put("API_PATH", sapUrl);
allJson.put("headers", headJson);
return allJson.toJSONString();
}
@ -50,7 +44,6 @@ public class SapUtil {
allJson.put("API_METHOD", "POST");
allJson.put("API_DATA", jsonObj);
allJson.put("API_PATH", sapUrl);
allJson.put("headers", headJson);
return allJson;
}
@ -66,6 +59,8 @@ public class SapUtil {
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json"); // 设置内容类型
connection.setRequestProperty("x-esb-apikey", apikey);
connection.setRequestProperty("x-esb-env", env);
// 设置 Basic Auth
String auth = sapUser + ":" + sapPassword;