|
|
@@ -8,6 +8,8 @@ import org.apache.http.impl.client.HttpClientBuilder;
|
|
8
|
8
|
import org.apache.http.util.EntityUtils;
|
|
9
|
9
|
import org.slf4j.Logger;
|
|
10
|
10
|
import org.slf4j.LoggerFactory;
|
|
|
11
|
+import org.springframework.http.HttpHeaders;
|
|
|
12
|
+import org.springframework.web.client.RestTemplate;
|
|
11
|
13
|
|
|
12
|
14
|
import java.io.IOException;
|
|
13
|
15
|
import java.util.Iterator;
|
|
|
@@ -105,35 +107,24 @@ public class HttpUtil {
|
|
105
|
107
|
|
|
106
|
108
|
/**
|
|
107
|
109
|
* 使用springframework的RestTemplate发送http
|
|
|
110
|
+ * http使用无参构造;https需要使用有参构造
|
|
108
|
111
|
*
|
|
109
|
|
- * @param wsdlURL
|
|
110
|
|
- * 请求URL
|
|
111
|
|
- * @param contentType
|
|
112
|
|
- * 如:application/json;charset=utf8
|
|
113
|
|
- * @param content
|
|
114
|
|
- * 数据内容
|
|
|
112
|
+ * @param wsdlURL 请求URL
|
|
|
113
|
+ * @param contentType 如: application/x-www-form-urlencoded
|
|
|
114
|
+ * @param content 数据内容
|
|
|
115
|
+ * Content-Length: length
|
|
|
116
|
+ * key=string&CF=string&ZBS=string&DELV=string&RKDate=string&CCLX=string&DZFS=string&XZ=string&R0=string&S0=string&S1=string&Z0=string&BWSLL=string&LSPZ=string&TFCS=string&TSQK=string
|
|
115
|
117
|
* @DATE 2018年9月22日 下午10:30:48
|
|
116
|
118
|
*/
|
|
117
|
|
- /*public static String doHttpPostByRestTemplate(final String wsdlURL, final String contentType, final String content) {
|
|
118
|
|
- // http使用无参构造;https需要使用有参构造
|
|
|
119
|
+ public static String doHttpPostByRestTemplate(final String wsdlURL, final String contentType, final String content) {
|
|
119
|
120
|
RestTemplate restTemplate = new RestTemplate();
|
|
120
|
|
- // 解决中文乱码
|
|
121
|
|
- List<HttpMessageConverter<?>> converterList = restTemplate.getMessageConverters();
|
|
122
|
|
- converterList.remove(1);
|
|
123
|
|
- HttpMessageConverter<?> converter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
|
|
124
|
|
- converterList.add(1, converter);
|
|
125
|
|
- restTemplate.setMessageConverters(converterList);
|
|
126
|
121
|
// 设置Content-Type
|
|
127
|
122
|
HttpHeaders headers = new HttpHeaders();
|
|
128
|
|
- headers.remove("Content-Type");
|
|
129
|
123
|
headers.add("Content-Type", contentType);
|
|
130
|
|
- // 数据信息封装
|
|
131
|
124
|
// 注意:和doHttpPostByHttpClient方法用的不是同一个HttpEntity
|
|
132
|
|
- org.springframework.http.HttpEntity<String> formEntity = new org.springframework.http.HttpEntity<String>(
|
|
133
|
|
- content, headers);
|
|
134
|
|
- String result = restTemplate.postForObject(wsdlURL, formEntity, String.class);
|
|
|
125
|
+ String result = restTemplate.postForObject(wsdlURL, content, String.class);
|
|
135
|
126
|
return result;
|
|
136
|
|
- }*/
|
|
|
127
|
+ }
|
|
137
|
128
|
|
|
138
|
129
|
/**
|
|
139
|
130
|
* 封装的get请求,暂时只支持map传参,并且value只支持基本类型和String
|