Commit 8a3e7675 authored by 赵啸非's avatar 赵啸非

修改配置文件

parent 4b4be57a
...@@ -8,6 +8,7 @@ import com.mortals.xhx.busiz.rsp.ApiResp; ...@@ -8,6 +8,7 @@ import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.common.code.ApiRespCodeEnum; import com.mortals.xhx.common.code.ApiRespCodeEnum;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.*; import okhttp3.*;
import org.apache.http.util.TextUtils;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -175,10 +176,14 @@ public class ProxyController { ...@@ -175,10 +176,14 @@ public class ProxyController {
} }
} else if ("get".equalsIgnoreCase(method)) { } else if ("get".equalsIgnoreCase(method)) {
Map<String, String> map = req.toJavaObject(Map.class);
String bodyParams = getBodyParams(map);
//url拼接参数 //url拼接参数
Request.Builder requestBuilder = new Request.Builder() Request.Builder requestBuilder = new Request.Builder()
.put(requestBody) .url(url+bodyParams)
.url(url)
.get(); .get();
// 透传 Headers(过滤掉 Host 避免冲突) // 透传 Headers(过滤掉 Host 避免冲突)
headers.forEach((key, value) -> { headers.forEach((key, value) -> {
...@@ -213,6 +218,34 @@ public class ProxyController { ...@@ -213,6 +218,34 @@ public class ProxyController {
} }
/**
* 添加参数
*
* @param bodyParams
* @return
*/
private String getBodyParams(Map<String, String> bodyParams) {
//1.添加请求参数
//遍历map中所有参数到builder
if (bodyParams != null && bodyParams.size() > 0) {
StringBuffer stringBuffer = new StringBuffer("?");
for (String key : bodyParams.keySet()) {
if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(bodyParams.get(key))) {
//如果参数不是null并且不是"",就拼接起来
stringBuffer.append("&");
stringBuffer.append(key);
stringBuffer.append("=");
stringBuffer.append(bodyParams.get(key));
}
}
return stringBuffer.toString();
} else {
return "";
}
}
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -63,10 +63,24 @@ Content-Type: application/json ...@@ -63,10 +63,24 @@ Content-Type: application/json
} }
###透传代理接口 ###透传代理接口
POST {{baseUrl}}/proxy/post?path=/entservice/ent/life/cycle/interlist&method=post POST {{baseUrl}}/proxy/post
Content-Type: application/json Content-Type: application/json
{"page": 1, "size": 10} {"page": 1,
"size": 10,
"path": "/entservice/ent/life/cycle/interlist",
"method": "post"
}
###透传代理接口get
POST {{baseUrl}}/proxy/post
Content-Type: application/json
{
"id": 1,
"path": "/entservice/ent/life/cycle/interinfo",
"method": "get"
}
### ###
......
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