Welcome to OGeek Q&A 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...