Skip to content

Instantly share code, notes, and snippets.

@carousel
Created March 30, 2017 15:14
Show Gist options
  • Save carousel/757d6a9202184eb3a39eae3f6f48ae36 to your computer and use it in GitHub Desktop.
Save carousel/757d6a9202184eb3a39eae3f6f48ae36 to your computer and use it in GitHub Desktop.
<?php
require "../vendor/autoload.php";
use Symfony\Component\HttpFoundation\Request;
function curlProxy($params = null)
{
$request = Request::createFromGlobals();
$data = json_decode($request->getContent());
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt_array($curl, array(
CURLOPT_URL => $data->url,
CURLOPT_CUSTOMREQUEST => $data->type,
CURLOPT_POSTFIELDS => $data->data,
CURLOPT_HTTPHEADER => $data->headers,
));
$response = curl_exec($curl);
$err = curl_error($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$status = json_encode(['status' => $status]);
$response = array_merge(json_decode($response, true), json_decode($status, true));
echo json_encode($response);
}
}
curlProxy();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment