如何将HTTP Basic Auth与HTTP-CLIENT一起使用?

发布于 2025-02-14 00:55:50 字数 633 浏览 1 评论 0原文

我想使用 http-client 使HTTP请求等于:

curl -u 'user:pass' 'https://api.example.net/a/b/c'

我已经阅读了HTTP-CLIENT的文档,以及 intarweb uri-common ,但我仍然不确定如何实现这一目标。

我可以看到可以使用make-uri设置用户名和密码,但是我不确定这是否是最佳选择。

如果有多种方法可以做到这一点,我对多个解决方案开放,但是优选一个惯用的答案。

I want to use http-client to make an HTTP request equivalent to:

curl -u 'user:pass' 'https://api.example.net/a/b/c'

I have read the docs for http-client, as well as for intarweb and uri-common, but I am still unsure of how to achieve this.

I can see that it's possible to set a username and password with make-uri, but I'm not sure if that's the best option.

I'm open to multiple solutions if there is more than one way to do it, but an idiomatic answer is preferable.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木槿暧夏七纪年 2025-02-21 00:55:50
(define user "user")
(define pass "pass")

(determine-username/password
 (lambda (uri realm)
   (values user pass)))

参见 https://wiki.call-call-cc.org/eggref/eggref/eggreffref /5/http-client#authentication-support 有关技术细节。

(define user "user")
(define pass "pass")

(determine-username/password
 (lambda (uri realm)
   (values user pass)))

See https://wiki.call-cc.org/eggref/5/http-client#authentication-support for the technical details.

稀香 2025-02-21 00:55:50

正如文档所说,

默认值是从URI提取用户名和密码组件的过程“

。使用输入 - 重复和朋友接受字符串,URI对象或请求 - 您将传递最简单的事情。

As the docs say,

the default value is a procedure which extracts the username and password components from the URI"

So, setting the password with make-uri is definitely supported and probably the simplest way in general. This is why with-input-from-request and friends accept either a string, an URI object or a request - you pass in the simplest thing that can work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文