HubSpot Webhook 到 aws ec2 ubuntu 服务器上的 PHP
HubSpot Webhook to PHP on aws ec2 ubuntu server
我正在使用 aws ec2 服务器 (ubuntu)。它设置为对所有流量开放。我正在尝试从 HubSpot 获取我的 Webhook 以连接到我的 php 页面以收集数据。我已经使用推荐的 RequestBin 站点测试了这个 webhook,所有数据都很好。因此,这导致认为它是我的代码,或者可能是在用于通过终端连接到它的服务器上使用 SSL。
我的php代码是...
<?php
# taking data from HubSpot's webhook
//$hookData = json_decode(file_get_contents("php://input"), ture);
//$_POST = json_decode(file_get_contents("http://requestb.in/150jn861")); // does not get anything
//$_POST = file_get_contents('http://requestb.in/150jn861'); // writes to file the string "ok"
$_POST = json_decode(file_get_contents("php://input"), ture);
$file = fopen("datadump1.txt", "w");
fwrite($file, $_POST);
fclose($file);
var_dump($_POST); // test input
echo "\nTest completed\n";
?>
我在这里找到了 2 个关于 webhooks 和 hubspot 的帖子,但修复没有奏效。如您所见,我一直在测试多项内容,但没有任何效果。由于这是 aws ec2,我无法使用 var_dump 或 echo 来真正测试我想要的效果。我以前从未使用过这种类型的环境。预先感谢您提供的任何帮助。
这对我来说是一个很大的疏忽。我没有考虑 ubuntu 中的权限。在使用本地文件和 cRUL 对我的 testPHP 文件进行测试后,我解决了这个问题。使用 "sudo chmod -R 777 /var/www/html/testPHP.php" 更改权限,然后使用本地 POST 我创建了一个文件,其中包含数据。这是我给任何想要它的人的代码;并且不要忘记 UBUNTU 中的权限。哈哈哈
<?php
# taking data from HubSpot's webhook
$hookData = file_get_contents("php://input");
$file = fopen('datadump.json','w') or die("Unable to open file!");
fwrite($file, $hookData);
fclose($file);
//var_dump($hookData); // test input
echo "\nTest completed\n" . $hookData;
?>
在我的 POST 文件中...
?php
$myObj = null;
$myObj->name = "Name";
$myObj->age = 32;
$myObj->city = "New York";
$myJSON = json_encode($myObj);
//API Url
$url = 'REMOVED; put your URL here';
//Initiate cURL.
$ch = curl_init($url);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $myJSON);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//Execute the request
$result = curl_exec($ch);
?>
我正在使用 aws ec2 服务器 (ubuntu)。它设置为对所有流量开放。我正在尝试从 HubSpot 获取我的 Webhook 以连接到我的 php 页面以收集数据。我已经使用推荐的 RequestBin 站点测试了这个 webhook,所有数据都很好。因此,这导致认为它是我的代码,或者可能是在用于通过终端连接到它的服务器上使用 SSL。
我的php代码是...
<?php
# taking data from HubSpot's webhook
//$hookData = json_decode(file_get_contents("php://input"), ture);
//$_POST = json_decode(file_get_contents("http://requestb.in/150jn861")); // does not get anything
//$_POST = file_get_contents('http://requestb.in/150jn861'); // writes to file the string "ok"
$_POST = json_decode(file_get_contents("php://input"), ture);
$file = fopen("datadump1.txt", "w");
fwrite($file, $_POST);
fclose($file);
var_dump($_POST); // test input
echo "\nTest completed\n";
?>
我在这里找到了 2 个关于 webhooks 和 hubspot 的帖子,但修复没有奏效。如您所见,我一直在测试多项内容,但没有任何效果。由于这是 aws ec2,我无法使用 var_dump 或 echo 来真正测试我想要的效果。我以前从未使用过这种类型的环境。预先感谢您提供的任何帮助。
这对我来说是一个很大的疏忽。我没有考虑 ubuntu 中的权限。在使用本地文件和 cRUL 对我的 testPHP 文件进行测试后,我解决了这个问题。使用 "sudo chmod -R 777 /var/www/html/testPHP.php" 更改权限,然后使用本地 POST 我创建了一个文件,其中包含数据。这是我给任何想要它的人的代码;并且不要忘记 UBUNTU 中的权限。哈哈哈
<?php
# taking data from HubSpot's webhook
$hookData = file_get_contents("php://input");
$file = fopen('datadump.json','w') or die("Unable to open file!");
fwrite($file, $hookData);
fclose($file);
//var_dump($hookData); // test input
echo "\nTest completed\n" . $hookData;
?>
在我的 POST 文件中...
?php
$myObj = null;
$myObj->name = "Name";
$myObj->age = 32;
$myObj->city = "New York";
$myJSON = json_encode($myObj);
//API Url
$url = 'REMOVED; put your URL here';
//Initiate cURL.
$ch = curl_init($url);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $myJSON);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//Execute the request
$result = curl_exec($ch);
?>