cURL上的-u标志实际上是做什么的? [英] What is -u flag on cURL actually doing?
问题描述
我正在查看Stripe的cURL示例以获取事件信息。
I'm looking at Stripe's cURL example for getting info on an event.
他们让我这样做:
curl https://api.stripe.com/v1/events/evt_123 \
-u sk_test_somekey:
cURL文档指出 -u
确实执行 USER:PASSWORD
。
The documentation for cURL states that -u
does USER:PASSWORD
.
当我尝试将其发送为 -d
或作为查询?
,Stripe的API说我缺少标头。
When I tried sending this as -d
or as a query ?
, Stripe's API says that I'm missing a header. This doesn't seem right.
我也不明白用户名后面是否缺少密码。如果我发送的cURL不带:
,则会提示我输入密码。击中Enter键(未输入任何字符),可以得到预期的响应。
I don't understand the lack of password after the username, either. If I send that cURL without the :
, I am prompted for a password. Hitting enter (no characters inputted), gets me the expected response.
因此, -u
到底在做什么这样我就可以在我的代码中模仿这个调用了吗?
So, what exactly is -u
doing so I can imitate this call in my code?
推荐答案
curl -u
将 username:password
字符串编码为base-64字符串,该字符串在 Authorization
标头中传递,如下所示:
curl -u
encodes the username:password
string into a base-64 string which is passed in the Authorization
header, like so:
GET / HTTP/1.1
Host: example.com
Accept: text/html
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
这不容易浏览,但也不是加密。拥有 base 64解码器的任何人都可以看到用户名和密码,因此请确保您进行了设置HTTPS。
This isn't easy to skim, but it's not encryption either. Anyone with a base 64 decoder can see the username and password, so make sure you set up HTTPS.
您的HTTP库可能具有为您执行此操作的功能。
Your HTTP library probably has a function that does this for you.
这篇关于cURL上的-u标志实际上是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!