0

为什么以下结果会导致“未经授权”响应:

 webClient
            .getAbs("http://hello.com")
            .basicAuthentication("user", "pw")
            .rxSend()
            .subscribe();

而以下工作正常:

 webClient
                .getAbs("http://hello.com")
                .putHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("user:pw".getBytes()) )
                .rxSend()
                .subscribe();
4

2 回答 2

2

这是实现basicAuthentication

    Buffer buff = Buffer.buffer().appendBuffer(id).appendString("-").appendBuffer(password);
    String credentials =  new String(Base64.getEncoder().encode(buff.getBytes()));
    return putHeader(HttpHeaders.AUTHORIZATION.toString(), "Basic " + credentials);

user-pw不放user:pw

于 2019-07-21T06:38:43.033 回答
0

方法描述与当前实现冲突,因为它说“用冒号连接”,所以我猜这是一个错误。我目前使用的是 3.6.3 版。

  /**
   * Configure the request to perform basic access authentication.
   * <p>
   * In basic HTTP authentication, a request contains a header field of the form 'Authorization: Basic &#60;credentials&#62;',
   * where credentials is the base64 encoding of id and password joined by a colon.
   * </p>
   *
   * @param id the id
   * @param password the password
   * @return a reference to this, so the API can be used fluently
   */
  @Fluent
  HttpRequest<T> basicAuthentication(String id, String password);
于 2019-07-22T08:45:49.700 回答