【问题标题】:Does Authorization in HttpPost is required everytime?每次都需要 HttpPost 中的授权吗?
【发布时间】:2019-02-18 22:56:07
【问题描述】:

我有一个简单的 http 邮政编码。我有一些基本问题。

CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Authorization", "Basic username:password");
httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setEntity(entity);
CloseableHttpResponse response = httpClient.execute(httpPost); 
httpClient.close();

是否需要为每个发布请求指定授权?一旦为第一个请求建立连接,有没有办法为后续的发布请求重用授权凭证?服务器是否在一段时间内保持特定客户端的授权处于活动状态?

【问题讨论】:

    标签: java apache https apache-httpclient-4.x


    【解决方案1】:

    取决于您的 http 服务器代码以及它如何处理每个请求;最简单的方法可能是在服务器的响应中设置一个cookie(或其他标识符值),然后在第一次成功授权后在连续请求中发送该值;

    【讨论】:

      猜你喜欢
      • 2014-10-31
      • 1970-01-01
      • 2014-11-05
      • 2016-08-04
      • 2021-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多