捕获从bash到PHP的cURL请求
我有几个bash脚本将信息从服务器发送到远程PHP脚本。我想为这些请求添加某种标记化/授权 下面是通过cURL发送JSON格式信息的bash脚本示例:捕获从bash到PHP的cURL请求,php,bash,curl,Php,Bash,Curl,我有几个bash脚本将信息从服务器发送到远程PHP脚本。我想为这些请求添加某种标记化/授权 下面是通过cURL发送JSON格式信息的bash脚本示例: echo "${infoArr}" | curl -sS -A "$(hostname)" --request POST "${api_url}" \ -H "Content-Type: application/json" \ -d @- 下面是一个用PHP编写的接
echo "${infoArr}" | curl -sS -A "$(hostname)" --request POST "${api_url}" \
-H "Content-Type: application/json" \
-d @-
下面是一个用PHP编写的接收端:
<?php
$data = json_decode(file_get_contents('php://input'), true);
...
只需在如下标题中发送令牌身份验证
echo "${infoArr}" | curl -sS -A "$(hostname)" --request POST "${api_url}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer __YOUR_AUTH_TOKEN_HERE__"
-d @-
在PHP中,您可以使用函数getallheaders()
给你
<?php
$headers = getallheaders();
/*
* Place for authorization methods
*/
$data = json_decode(file_get_contents('php://input'), true);
...