我使用的是Unirest Java客户端,如下所示,用于连接到外部API:
public static String loginAsAdmin(String authenticationURL , String userName , String password){
Map<String,String> creds = new HashMap<>();
creds.put("username", userName);
creds.put("password",password);
HttpResponse<JsonNode> jsonResponse
= Unirest.post(authenticationURL).header("Content-Type","application/json")
.body(creds)
.asJson();
return jsonResponse.getBody().toString();
}但是,当我运行代码时,我会得到以下错误:
kong.unirest.UnirestException: org.apache.http.client.ClientProtocolException
堆栈跟踪:
kong.unirest.UnirestException: org.apache.http.client.ClientProtocolException
at kong.unirest.DefaultInterceptor.onFail(DefaultInterceptor.java:43)
at kong.unirest.apache.ApacheClient.request(ApacheClient.java:133)
at kong.unirest.BaseRequest.asJson(BaseRequest.java:232)有关信息(我使用以下Unirest依赖项):
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.6.00</version>
</dependency>发布于 2020-03-18 05:47:28
奇怪的是,这个错误信息实际上是误导性的。这个问题的原因是错误的结束URL,这反过来是给404。我用适当的URL替换它并使其工作正常。也许,最单一的错误消息传递需要正确地对待这一点,以表示正确的错误。
https://stackoverflow.com/questions/60407137
复制相似问题