如何将HTTP Basic Auth与HTTP-CLIENT一起使用?
我想使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
参见 https://wiki.call-call-cc.org/eggref/eggref/eggreffref /5/http-client#authentication-support 有关技术细节。
See https://wiki.call-cc.org/eggref/5/http-client#authentication-support for the technical details.
正如文档所说,
。使用输入 - 重复和朋友接受字符串,URI对象或请求 - 您将传递最简单的事情。
As the docs say,
So, setting the password with
make-uri
is definitely supported and probably the simplest way in general. This is whywith-input-from-request
and friends accept either a string, an URI object or a request - you pass in the simplest thing that can work.