私は外部APIに接続するために以下のように使用しているUnirest Javaクライアントを使用しています:
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エラーメッセージングは、これを適切に処理して、適切な間違いを示す必要があります。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加