[英]What's the difference between curl's --user and --data option?
So to start, I was trying to make a bash script to login to a website every n days to bypass a weird geo-blocking. 因此,一开始,我试图制作一个bash脚本,每隔n天登录一次网站,以绕过奇怪的地理封锁。
But when I start googling around and research about how to login to a website using curl, I see two ways of doing them. 但是,当我开始四处搜寻并研究如何使用curl登录网站时,我看到了两种方法。
curl -u "foo:fooPassword" example.com
or 要么
curl -d "username=foo&password=fooPassword" example.com
well, in my use case, only the latter works, but I wonder what are the differences between these two options. 好吧,在我的用例中,只有后者有效,但是我想知道这两个选项之间有什么区别。
What are their preferred usecases? 他们首选的用例是什么?
Do they both do different things for different kinds of authentication? 他们对于不同的身份验证是否都做不同的事情?
Can -d, perhaps with some other options, replace --user? -d(也许还有其他选项)可以代替--user吗? or vice versa?
或相反亦然?
It seems to me that these two things can become easily mixed in my brain, so I want to see the differences between these two things 在我看来,这两件事很容易在我的大脑中混合,所以我想看看这两件事之间的区别
The --user
option sets the HTTP Authorization
header , which is used for HTTP basic authentication. --user
选项设置HTTP Authorization
标头 ,该标头用于HTTP基本身份验证。
The --data
option sets data that will be submitted in the body of an HTTP POST
request. --data
选项设置将在HTTP POST
请求的正文中提交的数据。 Many web applications implement their own authentication mechanisms using this method rather than relying on HTTP basic authentication, because this allows them a much higher degree of control over the process (eg, time based expiration of credentials, the ability to log out, etc). 许多Web应用程序使用此方法而不是依靠HTTP基本身份验证来实现自己的身份验证机制,因为这使它们可以对过程进行更高程度的控制(例如,基于时间的凭据到期,注销能力等)。 The
--data
option can be used to send any arbitrary data to the remote server; --data
选项可用于将任意数据发送到远程服务器。 it's not limited to just sending usernames and passwords. 它不仅限于发送用户名和密码。
Which of these two mechanisms is required depends entirely on the particular web service with which you are interacting. 这两种机制中的哪一种完全取决于您要与之交互的特定Web服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.