Vertx HttpRequest .basicAuthentication() 与 .putHeader("Authorization", "...")
Vertx HttpRequest .basicAuthentication() vs .putHeader("Authorization", "...")
为什么以下结果会导致 "Unauthorized" 响应:
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();
这是 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
。
方法描述与当前实现冲突,因为它说"joined by a colon",所以我猜这是一个错误。我目前使用的是 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 <credentials>',
* 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);
为什么以下结果会导致 "Unauthorized" 响应:
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();
这是 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
。
方法描述与当前实现冲突,因为它说"joined by a colon",所以我猜这是一个错误。我目前使用的是 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 <credentials>',
* 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);