簡體   English   中英

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

[英]Unirest Java Client : kong.unirest.UnirestException: org.apache.http.client.ClientProtocolException

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

奇怪的是,這個錯誤信息實際上是誤導性的。 這個問題的原因是錯誤的終結 URL,反過來又給出了404 我用正確的 URL 替換並且它工作正常。 也許 unirest 錯誤消息需要正確對待它以表示正確的錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM