首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Unirest : org.apache.http.client.ClientProtocolException :kong.unirest.UnirestException

Unirest : org.apache.http.client.ClientProtocolException :kong.unirest.UnirestException
EN

Stack Overflow用户
提问于 2020-02-26 05:07:12
回答 1查看 2.6K关注 0票数 0

我使用的是Unirest Java客户端,如下所示,用于连接到外部API:

代码语言:javascript
复制
 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

堆栈跟踪:

代码语言:javascript
复制
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依赖项):

代码语言:javascript
复制
 <dependency>
            <groupId>com.konghq</groupId>
            <artifactId>unirest-java</artifactId>
            <version>3.6.00</version>
        </dependency>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-18 05:47:28

奇怪的是,这个错误信息实际上是误导性的。这个问题的原因是错误的结束URL,这反过来是给404。我用适当的URL替换它并使其工作正常。也许,最单一的错误消息传递需要正确地对待这一点,以表示正确的错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60407137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档