Thursday, July 6, 2017

PHP http query

<?php

$header = "Content-type: application/json\r\n"
. "Content-Length: " . strlen($data) . "\r\n"
;


$context = stream_context_create([
        'http' => [
                'method'  => 'POST',
                'ignore_errors' => true,
                'header'=> $header,
                'content' => $data,
        ],
        'ssl' => [
                // set some SSL/TLS specific options
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
        ],
]);

$result = file_get_contents('http://example.com/', false, $context);

No comments: