我正在使用最新的 apache http:<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient-osgi</artifactId> <version>4.5.6</version></dependency><dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore-osgi</artifactId> <version>4.4.10</version></dependency>我有以下操作:public void store(InputStream input) throws IOException { HttpClientBuilder builder = HttpClientBuilder.create(); if (StringUtils.isNotBlank(username)) { CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username.trim(), StringUtils.trimToEmpty(password)); provider.setCredentials(AuthScope.ANY, credentials); builder.setDefaultCredentialsProvider(provider); } HttpClient client = builder.build(); HttpPost post = new HttpPost(uri); post.setEntity(new InputStreamEntity(input)); HttpResponse response = client.execute(post);} 在基本身份驗證處于活動狀態之前,一切正常,但是,在添加基本身份驗證后,我收到以下錯誤:引起:org.apache.http.client.NonRepeatableRequestException:無法使用不可重復的請求實體重試請求。在 org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:226) 在 org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) 在 org.apache.http.impl .execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient) .java:185) ... 6 更多我發現了以下錯誤報告:https://github.com/http-builder-ng/http-builder-ng/issues/10,但是它被分配給另一個問題。導致錯誤的原因是什么?如何在 apache httpclient 中使用基本身份驗證?我不知道什么是“可重復的 HTTP 請求”,據我所知,客戶端需要設置的只是 Authorization 標頭。我是否可能在服務器上錯誤配置了某些內容,因此它需要“可重復”的 HTTP 請求?
添加回答
舉報
0/150
提交
取消