Skip to content

Commit eda913b

Browse files
committed
split json or html
1 parent 25ed94e commit eda913b

File tree

1 file changed

+26
-4
lines changed
  • springboot-starter/src/main/java/com/codingapi/springboot/framework/rest

1 file changed

+26
-4
lines changed

springboot-starter/src/main/java/com/codingapi/springboot/framework/rest/SessionClient.java

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.codingapi.springboot.framework.rest;
22

3+
import com.alibaba.fastjson.JSONObject;
34
import com.codingapi.springboot.framework.rest.param.RestParamBuilder;
45
import com.codingapi.springboot.framework.rest.properties.HttpProxyProperties;
56
import org.springframework.http.HttpHeaders;
67
import org.springframework.http.HttpStatus;
8+
import org.springframework.http.MediaType;
79
import org.springframework.http.ResponseEntity;
810

911
import java.net.URI;
@@ -63,16 +65,36 @@ public SessionClient addHeader(String key, String value){
6365
return this;
6466
}
6567

66-
public String post(String url, RestParamBuilder restParam){
68+
public String postForm(String url, RestParamBuilder restParam){
69+
httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
6770
return httpClient.post(url,httpHeaders,restParam.toFormRequest());
6871
}
6972

70-
public String get(String url){
71-
return get(url,null);
73+
public String postJson(String url, RestParamBuilder restParam){
74+
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
75+
return httpClient.post(url,httpHeaders,restParam.toJsonRequest());
7276
}
7377

74-
public String get(String url,RestParamBuilder restParam){
78+
public String postJson(String url, JSONObject requestBody){
79+
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
80+
return httpClient.post(url,httpHeaders,requestBody);
81+
}
82+
83+
public String getJson(String url){
84+
return getJson(url,null);
85+
}
86+
87+
public String getHtml(String url){
88+
return getHtml(url,null);
89+
}
90+
91+
public String getHtml(String url,RestParamBuilder restParam){
92+
httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
7593
return httpClient.get(url,httpHeaders,restParam!=null?restParam.toFormRequest():null);
7694
}
7795

96+
public String getJson(String url,RestParamBuilder restParam){
97+
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
98+
return httpClient.get(url,httpHeaders,restParam!=null?restParam.toFormRequest():null);
99+
}
78100
}

0 commit comments

Comments
 (0)