String url = "http://www.qq.com";
String reqBody = "";
final HttpPatch httpUriRequest = new HttpPatch(url);
httpUriRequest.setHeader("cookie", "token=" + token);
httpUriRequest.setHeader("content-type", "application/json;charset=UTF-8");
httpUriRequest.setEntity(new StringEntity(reqBody));
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(120_000).setConnectTimeout(120_000).build();
httpUriRequest.setConfig(requestConfig);
HttpResponse response = httpClient.execute(httpUriRequest);
HttpEntity entity = response.getEntity();
if (entity != null) {
final String body = EntityUtils.toString(entity, CharEncoding.UTF_8);
log.info("depApp,respBody={}", body);
return body;
} else {
log.info("depApp,respBody empty");
return "entity empty";
}
httpclient发起patch请求
最新推荐文章于 2025-10-07 09:33:01 发布
本文介绍了如何使用HttpPatch进行HTTP请求,设置了超时和头信息,重点展示了设置cookie和content-type的过程,并处理了响应结果。
1286

被折叠的 条评论
为什么被折叠?



