$url = 'https://xxxxxxxxx.com/';
$method = "POST";
$params = [
"param" => "1"
];
$query_string = json_encode($params);
$curl = curl_init();
if ($method === 'POST') {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $query_string);
} else {
$url .= ($query_string ? '?'.$query_string : '');
curl_setopt($curl, CURLOPT_HTTPGET, true);
}
$connect_timeout = 5;
$timeout = 10;
$headers += array(
'Content-Type: application/json',
'Content-Length: ' . strlen($query_string)
);
curl_setopt($curl, CURLOPT_VERBOSE, true);
$verbose = fopen('php://temp', 'w+');
curl_setopt($curl, CURLOPT_STDERR, $verbose);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $connect_timeout);
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
$response_str = curl_exec($curl);
$errno = curl_errno($curl);
echo curl_errno($curl) . " >>> " . curl_error($curl);
rewind($verbose);
$verboseLog = stream_get_contents($verbose);
echo "Verbose information:\n<pre>", htmlspecialchars($verboseLog), "</pre>\n";
$http_code = intval(curl_getinfo($curl, CURLINFO_HTTP_CODE));
curl_close($curl);
echo $response;
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS");
file_put_contents('log.txt',print_r(getallheaders(),true)."\n\n",FILE_APPEND);
echo json_encode(["error" => 0]);
0 >>> Verbose information:
* Hostname in DNS cache was stale, zapped
* Trying xxx.xxx.xxx.xxx...
* TCP_NODELAY set
* Connected to xxxxxxxxx.com (xxx.xxx.xxx.xxx) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: CN=xxxxxxxxx.com
* start date: Apr 10 16:40:19 2020 GMT
* expire date: Jul 9 16:40:19 2020 GMT
* subjectAltName: host "xxxxxxxxx.com" matched cert's "xxxxxxxxx.com"
* issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
* SSL certificate verify ok.
> POST /receiver.php HTTP/1.1
Host: xxxxxxxxx.com
Accept: */*
Content-Type: application/json
Content-Length: 60
* upload completely sent off: 60 out of 60 bytes
< HTTP/1.1 200 OK
< Server: nginx
< Date: Sat, 11 Apr 2020 10:03:32 GMT
< Content-Type: text/html; charset=UTF-8
< Content-Length: 0
< Connection: keep-alive
< Keep-Alive: timeout=60
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS
<
* Curl_http_done: called premature == 0
* Connection #0 to host xxxxxxxxx.com left intact
{"error":0}