2017-05-12 13 views
0

私はaws ec2サーバー(ubuntu)で作業しています。これは、すべてのトラフィックに対して同様に開くように設定されています。私はHubSpotからWebhookを取得して、データを収集するために私のPHPページに接続しようとしています。私はこのWebhookを推奨されたRequestBinサイトでテストしました。すべてのデータはうまくいきます。だから、これは自分のコードや、ターミナルを介して接続するために使用されるサーバー上のSSLの使用を考えるようになります。私のPHPコードがあるaws ec2 ubuntuサーバーでHubSpot Webhookに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の他の記事を発見したが、修正がうまくいきませんでした。あなたが見ることができるように、私は複数のものをテストしていますが、何も動かされていません。これはaws ec2なので、var_dumpやエコーを使って私が望むように実際にテストすることはできません。これまで私はこのタイプの環境を使ったことがありません。あなたが与えることができるすべての助けをありがとうございます。

答えて

0

これは私の目の前で大きなものでした。私はubuntuの権限を考慮していませんでした。ローカルファイルとcRULでtestPHPファイルをテストした後、私はこれを傷つけました。 "sudo chmod -R 777 /var/www/html/testPHP.php"でアクセス権を変更した後、ローカルのPOSTでファイルが作成され、データがそこにありました。ここにそれを望む誰のための私のコードです。 UBUNTUの場合は許可を守らないでください。私のPOSTファイル内HAHAHA

<?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; 
?> 

...

?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); 
?> 
関連する問題