Unirest Java客户端:kong.unirest.UnirestException:org.apache.http.client.ClientProtocolException

问题描述 投票:0回答:1

我正在使用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

Stacktrace:

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>
java spring rest-client unirest unirest-java
1个回答
0
投票

奇怪的是,此错误消息实际上是令人误解的。导致此问题的原因是错误的endpoing URL,该URL反过来给出了[[404。我将其替换为正确的URL及其正常工作。也许异常信息传递需要适当地处理以表示正确的错误。

© www.soinside.com 2019 - 2024. All rights reserved.