How to pass token in rest API?
This question already has an answer here:
How you can see in the request_headers I can see correctly in the header, but I can't catch it through the use of $_SERVER['Authorization'] or $_SERVER['HTTP_Authorization']
Every time you need to see the the headers, or even any other information that you think should be available, I suggest you debug it like this:
var_dump($_SERVER);
Most probably you'll find it as: $_SERVER['HTTP_AUTHORIZATION']
Note: this is case-sensitive! Php takes the headers, capitalizes the key, changes " -
" to " _
" and prepends " HTTP_
".
Note2: don't use a standard http header, like Authorization
for your custom made tokens. That is for HTTP Basic Authentication. If you do implement your custom token, then use your custom http header for it.
你可以通过-H
参数传递curl头文件,如下所示:
curl http://localhost/v1 -H "AUTH_USER: <token>"
链接地址: http://www.djcxy.com/p/21950.html
上一篇: 保护REST风格的Web服务网址
下一篇: 如何在其他API中传递令牌?