1
votes

I have some http request like this

$url = 'https://example.com/authentication';
$data = array('email' => 'value1', 'password' => 'value2');

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }

var_dump($result);

But i got error like this Warning: file_get_contents(https://example.com/authentication): failed to open stream: Connection refused

I read that curl can help, but i dont know how to implement it, thanks in advance

1
it's not a client error, it's related to the server. please run this command in the terminal telnet SERVER_IP_OR_URL 443 - Raftx24

1 Answers

0
votes

try this one for basic curl request

$data = array('email' => 'value1', 'password' => 'value2');
$contentType = 'application/x-www-form-urlencoded';
$HTTPCustomHeaders[] = 'Content-Type: '.trim($contentType);
$runfile = 'example.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $runfile);
curl_setopt($ch, CURLOPT_HTTPHEADER, $HTTPCustomHeaders);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$content = curl_exec ($ch);
curl_close ($ch); 
echo $content