gpt4 book ai didi

java - Vertx HttpRequest .basicAuthentication() 与 .putHeader ("Authorization"、 "...")

转载 作者:行者123 更新时间:2023-12-02 01:24:49 25 4
gpt4 key购买 nike

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

 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

关于java - Vertx HttpRequest .basicAuthentication() 与 .putHeader ("Authorization"、 "..."),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57096181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com