我正在尝试将cURL发布到Zapier网络钩子上。
Zapier被配置为,如果我键入它们的URL,就像so -- https://zapier.com/hooks/catch/n/abcd?email=foo@bar.com&guid=foobar
它会收到这个帖子,但是当我尝试用cURL做同样的事情时,它似乎没有收到它。
以下是我在cURL中发布的代码-->
<?php
// Initialize curl
$curl = curl_init();
// Configure curl options
$opts = array(
CURLOPT_URL => 'https://zapier.com/hooks/catch/n/abcd',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => 'guid='+ $_POST["guid"] + '&video_title=' + $_POST["video_title"] + '&email=' + $_POST["email"],
);
// Set curl options
curl_setopt_array($curl, $opts);
// Get the results
$result = curl_exec($curl);
// Close resource
curl_close($curl);
echo $result;
?>当我运行它时,它显示成功,但Zapier没有收到它。
在Zapier的文档中,有人给出了一个适当的cURL帖子的例子,比如so ->
curl -v -H "Accept: application/json" \
-H "Content-type: application/json" \
-X POST \
-d '{"first_name":"Bryan","last_name":"Helmig","age":27}' \
https://zapier.com/hooks/catch/n/Lx2RH/我猜我在PHP文件中遗漏了一些东西,帮助非常感激!
发布于 2013-08-28 08:48:04
您需要对要发送的数据进行json编码,并设置内容类型:
更改:
$opts = array(
CURLOPT_URL => 'https://zapier.com/hooks/catch/n/abcd',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => 'guid='+ $_POST["guid"] + '&video_title=' + $_POST["video_title"] + '&email=' + $_POST["email"],
);至:
$data = array('guid' => $_POST["guid"], 'video_title' => $_POST["video_title"], 'email' => $_POST["email"]);
$jsonEncodedData = json_encode($data);
$opts = array(
CURLOPT_URL => 'https://zapier.com/hooks/catch/n/abcd',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $jsonEncodedData,
CURLOPT_HTTPHEADER => array('Content-Type: application/json','Content-Length: ' . strlen($jsonEncodedData))
);这应该能行。
发布于 2013-08-28 08:44:24
如果您没有正确地发送POSTFIELDS,您需要使用.而不是+,而且您还应该对字符串进行url编码.
$opts = array(
CURLOPT_URL => 'https://zapier.com/hooks/catch/n/abcd',
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(array('guid' => $_POST['guid'], 'video_title' => $_POST['video_title'], 'email' => $_POST['email']))
);发布于 2019-10-30 14:59:16
你没有收到它在Zapier,因为你没有设置‘子键’结构。看看下面的图片中你需要做些什么。
请记住,在我的情况下,我想抓住'company_name'.您必须用自己的参数替换它。您还可以定义其他参数,甚至可以完全更改“子键”结构。

https://stackoverflow.com/questions/18483158
复制相似问题