如何使用curl设置授权头 [英] How to set the authorization header using curl

查看:199
本文介绍了如何使用curl设置授权头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用cURL传递授权标头? (不是PHP cURL扩展, / usr / bin / curl 中的可执行文件)。

How do I pass authorization header using cURL? (Not the PHP cURL extension, the executable in /usr/bin/curl).

推荐答案

http://curl.haxx.se/docs/httpscripting.html

请参阅第6部分。HTTP验证

See part 6. HTTP Authentication


HTTP验证

HTTP Authentication

HTTP身份验证是能够告诉服务器您的用户名和
密码,以便它可以验证您是否允许执行您的请求
做。 HTTP中使用的基本身份验证(默认为
使用的类型)是基于 的基本身份,这意味着它发送用户名和密码
只有轻微的混淆,但仍然完全可读的任何人嗅闻
你和远程服务器之间的网络。

HTTP Authentication is the ability to tell the server your username and password so that it can verify that you're allowed to do the request you're doing. The Basic authentication used in HTTP (which is the type curl uses by default) is plain text based, which means it sends username and password only slightly obfuscated, but still fully readable by anyone that sniffs on the network between you and the remote server.

告诉curl使用用户和密码

To tell curl to use a user and password for authentication:

curl --user name:password http://www.example.com

该网站可能需要一个不同的身份验证方法(检查服务器返回的头文件
),然后--ntlm, --digest,--negotiate甚至
--anyauth可能是适合你的选项。

The site might require a different authentication method (check the headers returned by the server), and then --ntlm, --digest, --negotiate or even --anyauth might be options that suit you.

有时你的HTTP访问只能通过使用HTTP
代理。这似乎在各个公司尤其常见。 HTTP代理
可能需要自己的用户和密码,以允许客户端通过Internet访问
。要指定curl,请运行类似:

Sometimes your HTTP access is only available through the use of a HTTP proxy. This seems to be especially common at various companies. A HTTP proxy may require its own user and password to allow the client to get through to the Internet. To specify those with curl, run something like:

curl --proxy-user proxyuser:proxypassword curl.haxx.se

如果您的代理需要使用NTLM方法进行身份验证,则
使用--proxy- ntlm,如果它需要摘要使用--proxy-digest。

If your proxy requires the authentication to be done using the NTLM method, use --proxy-ntlm, if it requires Digest use --proxy-digest.

如果你使用任何一个这些用户+密码选项,但省略密码
part,curl将会提示输入密码。

If you use any one these user+password options but leave out the password part, curl will prompt for the password interactively.

请注意,当程序运行时,其参数可能会在列出系统正在运行的进程时看到
。因此,如果您以纯命令行
选项传递他们的密码,其他用户可以
。有一些方法可以规避这种情况。

Do note that when a program is run, its parameters might be possible to see when listing the running processes of the system. Thus, other users may be able to watch your passwords if you pass them as plain command line options. There are ways to circumvent this.

值得注意的是,虽然这是HTTP认证的工作方式,但很多网站不会使用这个概念提供登录等。有关详细信息,请参阅下面的Web登录一章。$ / b>

It is worth noting that while this is how HTTP Authentication works, very many web sites will not use this concept when they provide logins etc. See the Web Login chapter further below for more details on that.

这篇关于如何使用curl设置授权头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆