我使用此功能
public static String postJson(String postUrl, String request) {
logger.info("postUrl = " + postUrl);
try {
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(postUrl);
logger.info("request = " + cutLogForStreaming(request));
StringEntity postingString = new StringEntity(request);
post.setEntity(postingString);
post.setHeader("Content-type", "application/json");
HttpResponse response = httpClient.execute(post);
String result = EntityUtils.toString(response.getEntity());
logger.info("response = " + cutLogForStreaming(result));
return result;
} catch (Exception e) {
logger.info(e.getCause());
logger.error("Exception:: " + e.toString() + " "+ Arrays.toString(e.getStackTrace()));
return null;
}
}
但是我调试它并抛出
在“ HttpClient httpClient = HttpClientBuilder.create()。build();“处的调用目标异常”]]
有人可以解释为什么以及如何解决?
我使用此函数public static String postJson(String postUrl,String request){logger.info(“ postUrl =” + postUrl);尝试{HttpClient httpClient = ...
我将通过HttpUrlConnection采用“经典”方式。