Ala*_*ano 28 authentication curl
来自cUrl docs:
-u, --user <user:password;options>
Specify the user name, password and optional login options to use for server authentication. Overrides -n, --netrc and --netrc-optional.
Run Code Online (Sandbox Code Playgroud)
它被翻译成什么,意味着如何在服务器上捕获它以验证用户:他们是GET还是POST参数?
语言并不重要,这个想法很重要.
del*_*eil 48
这一切都取决于身份验证方法,但对于最常见的方法 - Basic Auth和Digest Auth,这适用于ad hoc HTTP标头.以下是Basic Auth的示例:
curl -u john:pwd http://foo.com/misc
Run Code Online (Sandbox Code Playgroud)
这将使用相应的标头执行GET请求:
GET /misc HTTP/1.1
Authorization: Basic am9objpwd2Q=
User-Agent: curl/7.33.0
Host: foo.com
Accept: */*
Run Code Online (Sandbox Code Playgroud)
该Authorization标头包含服务器应该解析认证数据,BASE64解码[1]并使用.将使用POST请求设置相同的标头.您可以使用httpbin(1)等服务轻松测试它(请参阅/basic-auth/:user/:passwd端点).
摘要身份验证有点复杂,但也适用于HTTP标头:
401 Unauthorized包含一个WWW-Authenticate带有挑战的标题来解决,Authorization标头中,该标头必须在服务器端进行解析和验证.[1]:base64("john:pwd")- >am9objpwd2Q=
在 PHP/nginx 中,它在此数组元素中作为 Base64 编码字符串提供。它适用于 GET 和 POST (curl -X POST ) 方法。
$_SERVER['HTTP_AUTHORIZATION']
Run Code Online (Sandbox Code Playgroud)
要求:
curl http://127.0.0.1:8080/test.php -u arun:12345
Run Code Online (Sandbox Code Playgroud)
$_SERVER['HTTP_AUTHORIZATION'] 中的值:
Basic YXJ1bjoxMjM0NQ==
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
35843 次 |
| 最近记录: |