简体   繁体   中英

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.

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 -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? 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.

The --data option sets data that will be submitted in the body of an HTTP POST request. 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). The --data option can be used to send any arbitrary data to the remote server; 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM