亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

添加基本??身份驗證后的 NonRepeatableRequestException

添加基本??身份驗證后的 NonRepeatableRequestException

一只甜甜圈 2021-08-13 16:59:31
我正在使用最新的 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 請求?
查看完整描述

2 回答

?
千萬里不及你

TA貢獻1784條經驗 獲得超9個贊

我不同意 OP 自己的解決方案,因為它在某種程度上非常駭人聽聞,并且繞過了庫的憑證機制。

HTTP 實體有多種實體類型,如此處所述。因此,既然您知道,您不能在您的場景中使用可重復實體,那么如何使用自包含實體或使用緩沖區的包裝器。

您可以使用單線來實現這一點。沒有嘗試過,我認為正確的解決方案是:

post.setEntity(new BufferedHttpEntity(new InputStreamEntity(input)));


查看完整回答
1 反對 回復 2021-08-13
  • 2 回答
  • 0 關注
  • 257 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號