Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

curl - 使用带有用户名和密码的cURL?(Using cURL with a username and password?)

I want to access a URL which requires a username/password.

(我想访问一个需要用户名/密码的URL。)

I'd like to try accessing it with curl.

(我想尝试使用curl访问它。)

Right now I'm doing something like:

(现在我正在做类似的事情:)

curl http://api.somesite.com/test/blah?something=123

I get an error.

(我得到一个错误。)

I guess I need to specify a username and password along with the above command.

(我想我需要指定用户名和密码以及上述命令。)

How can I do that?

(我怎样才能做到这一点?)

  ask by user246114 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use the -u flag to include a username, and curl will prompt for a password:

(使用-u标志包含用户名,curl会提示输入密码:)

curl -u username http://example.com

You can also include the password in the command, but then your password will be visible in bash history:

(您还可以在命令中包含密码,但是您的密码将在bash历史记录中显示:)

curl -u username:password http://example.com

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...