Skip to content

Instantly share code, notes, and snippets.

@StancuFlorin
Created November 13, 2017 17:55
Show Gist options
  • Save StancuFlorin/1449c11ec6793f23b79529e0da82fc62 to your computer and use it in GitHub Desktop.
Save StancuFlorin/1449c11ec6793f23b79529e0da82fc62 to your computer and use it in GitHub Desktop.
<?php
$token = $_GET['t'];
if ($token !== "C7Ck9o4Fpi1Yh7YTCtk0") {
print_r("You need to specify the correct token.");
exit();
}
$data = json_decode(file_get_contents('php://input'), true);
$url = $data['url'];
$method = $data['method'];
if (empty($url) || empty($url)) {
print_r("You need to specify the URL and the HTTP method.");
exit();
}
$body = null;
if (!empty($data['body'])) {
$body = json_encode($data['body']);
}
$headers = "Content-Type: application/json";
if (!empty($data['headers'])) {
foreach ($data['headers'] as &$header) {
$headers = $headers . "\r\n" . $header['name'] . ": " . $header['value'];
}
}
print_r("Request Headers\r\n" . $headers . "\r\n");
print_r("Request URL: " . $url . "\r\n");
print_r("Request Method: " . $method . "\r\n");
print_r("Request Body\r\n" . $body . "\r\n");
$options = array(
'http' => array(
'header' => $headers,
'method' => $method,
'content' => $body,
'ignore_errors' => true
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
print_r("\r\nResponse Body\r\n" . $result);
?>
@StancuFlorin
Copy link
Author

StancuFlorin commented Nov 13, 2017

curl -XPOST -H "Content-type: application/json" -d '{
   "headers": [
      {
         "name": "MyFirstHeaderName",
         "value": "my_first_header_value"
      },
      {
         "name": "MySecondHeaderName",
         "value": "my_second_header_value"
      }
   ],
   "url": "http://api-that-require-headers.com",
   "method": "POST",
   "body": {
      "first_body_node": 123,
      "second_body_node": "my second body node value",
	  "third_body_node": {
		"node_from_another_object": "test"
	  }
   }
}' 'http://my-domain.com/ifttt.php?t=C7Ck9o4Fpi1Yh7YTCtk0'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment