【问题标题】:Unirest Java Client : kong.unirest.UnirestException: org.apache.http.client.ClientProtocolExceptionUnirest Java 客户端:kong.unirest.UnirestException:org.apache.http.client.ClientProtocolException
【发布时间】:2020-06-09 22:13:27
【问题描述】:

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

【问题讨论】:

    标签: java spring rest-client unirest unirest-java


    【解决方案1】:

    奇怪的是,这个错误信息实际上具有误导性。此问题的原因是错误的端点 URL,这反过来又给出了 404。我用正确的 URL 替换并且它工作正常。也许 unirest 错误消息需要正确处理这一点以表示正确的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-05
      • 2011-08-12
      • 2015-06-21
      • 2010-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多