MCPcopy Create free account
hub / github.com/0x727/DropLabTools / doPostRequest

Method doPostRequest

src/main/java/com/droplab/Utils/HttpUtils.java:210–249  ·  view source on GitHub ↗

执行post请求 @param url 请求URL地址 @param headers 请求头 @param jsonParams 请求JSON格式字符串参数 @return HTTP响应对象 @throws IOException 程序异常时抛出,由调用者处理

(String url, Map<String, String> headers, String jsonParams)

Source from the content-addressed store, hash-verified

208 * @throws IOException 程序异常时抛出,由调用者处理
209 */
210 private static Response doPostRequest(String url, Map<String, String> headers, String jsonParams) throws IOException {
211 if (null == url || url.isEmpty()) {
212 throw new RuntimeException("The request URL is blank.");
213 }
214
215 // 如果是Https请求
216 if (url.startsWith(HTTPS)) {
217 getTrust();
218 }
219 //Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 1080));
220 Proxy proxy = getProxy();
221 Connection connection=null;
222 if(proxy !=null){
223 if(!InfoUtils.ProxyUsername.equals("") && !InfoUtils.ProxyPassword.equals("")){
224 Authenticator.setDefault(new MyAuthenticator(InfoUtils.ProxyUsername,InfoUtils.ProxyPassword));
225 }
226 connection = Jsoup.connect(url).proxy(proxy);
227 }else {
228 connection = Jsoup.connect(url);
229 }
230 connection.method(Method.POST);
231 connection.timeout(TIME_OUT);
232 connection.ignoreHttpErrors(true);
233 connection.ignoreContentType(true);
234 connection.maxBodySize(0);
235
236 if (null != headers) {
237 connection.headers(headers);
238 }
239
240 if(Content_Type != null && !"".equals(Content_Type)){
241 connection.header(CONTENT_TYPE, Content_Type);
242 }else {
243 connection.header(CONTENT_TYPE, JSON_TYPE);
244 }
245 connection.requestBody(jsonParams);
246
247 Response response = connection.execute();
248 return response;
249 }
250
251 /**
252 * 普通表单方式发送POST请求

Callers 1

postMethod · 0.95

Calls 7

getTrustMethod · 0.95
getProxyMethod · 0.95
closeStreamMethod · 0.95
proxyMethod · 0.80
methodMethod · 0.80
headersMethod · 0.80
headerMethod · 0.80

Tested by

no test coverage detected