Zapier REST订阅挂钩无法在PHP中解析

时间:2019-09-04 23:43:04

标签: php rest api zapier

我正在设置一个Zapier订阅挂钩,这是它生成的代码供我测试...

const options = {
url: 'https://www.my-web-site-url.com/zapier/api/subscribe/hook',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-KEY': bundle.authData.api_key,
'Accept': 'application/json'
},
params: {
'api_key': bundle.authData.api_key
},
body: {
'helloWorld': '123123',
'hookUrl': bundle.targetUrl
}
}

return z.request(options)
.then((response) => {
response.throwForStatus();
const results = z.JSON.parse(response.content);

return results;
});

当我在Zapier中运行测试时,它成功地发布到了我的PHP脚本中,但是当我尝试解析我的Php脚本中的主体变量:“ hookUrl”或“ helloWorld”时,我只是空白(没有nada) 。

这是我简单的PHP代码:

 echo $_POST['helloWorld']; 

我在做错什么,因为我看不到为什么$ _POST ['helloWorld']不会呈现“ 123123”而不是“”。

1 个答案:

答案 0 :(得分:0)

$_POST数组仅针对内容类型为application/x-www-form-urlencodedmultipart/form-data的HTTP-POST请求填充。 [1]

我建议获取请求主体(它是json编码的字符串)并将其解码为数组。 [2]

$postdata = file_get_contents("php://input");

$request = json_decode($postdata, 1);

echo $request['helloWorld'];