简体   繁体   English

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

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

I am using Unirest Java client which I am using like below to connect to external API:我正在使用 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();
    }

but while I am running code I am getting following error:但是当我运行代码时,我收到以下错误:

kong.unirest.UnirestException: org.apache.http.client.ClientProtocolException 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)

For information ( I am using following Unirest dependency ):有关信息(我正在使用以下 Unirest 依赖项):

 <dependency>
            <groupId>com.konghq</groupId>
            <artifactId>unirest-java</artifactId>
            <version>3.6.00</version>
        </dependency>

Strange this error message was actually misleading.奇怪的是,这个错误信息实际上是误导性的。 Cause of this issue was wrong endpoing URL, which in turn was giving 404 .这个问题的原因是错误的终结 URL,反过来又给出了404 I replace with proper URL and its working fine.我用正确的 URL 替换并且它工作正常。 Perhaps unirest error messaging needs to treat this properly to denote proper mistake.也许 unirest 错误消息需要正确对待它以表示正确的错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.apache.http.client.ClientProtocolException - org.apache.http.client.ClientProtocolException HttpPost 中的 org.apache.http.client.ClientProtocolException - org.apache.http.client.ClientProtocolException in HttpPost HttpClient执行时出现org.apache.http.client.ClientProtocolException - org.apache.http.client.ClientProtocolException appears when HttpClient executes 调用AlchemyAPI时获取org.apache.http.client.ClientProtocolException - Getting org.apache.http.client.ClientProtocolException while calling AlchemyAPI Apache HttpComponents:org.apache.http.client.ClientProtocolException - Apache HttpComponents: org.apache.http.client.ClientProtocolException Spring WS-I / O错误:null; 嵌套的异常是org.apache.http.client.ClientProtocolException - Spring WS - I/O error: null; nested exception is org.apache.http.client.ClientProtocolException 使用httpclient 4.1.2连接到https会产生org.apache.http.client.ClientProtocolException - connection to https with httpclient 4.1.2 gives org.apache.http.client.ClientProtocolException Android Studio:Unirest-Java找不到类“ org.apache.http.impl.client.CloseableHttpClient” - Android Studio: Unirest-Java Could not find class 'org.apache.http.impl.client.CloseableHttpClient' 无法初始化主类,导致:java.lang.NoClassDefFoundError: com/mashape/unirest/http/exceptions/UnirestException [JAVA] - Unable to initialize main class, Caused by: java.lang.NoClassDefFoundError: com/mashape/unirest/http/exceptions/UnirestException [JAVA] java.lang.NoClassDefFoundError:使用jsonparser()时org / apache / http / client / ClientProtocolException - java.lang.NoClassDefFoundError: org/apache/http/client/ClientProtocolException while using the jsonparser()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM