API access on port 443 returning Connection timed out

0

I am configuring a webAPI and after configuring everything (id, key, signature, other data api requests) and authenticate by HEADER in php using json and CURL to post to the site the return is being Curl error: Failed to connect to 111.222.333.444 port 443: Connection timed out . My code:

<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);

//DADOS DE ACESSO
$id = "xxx";
$retailerName = "xxx";

$key = "xxx";

//PRODUTO
//vars of product:fictional data
$upc = "799366289999";
$amount = "20.00";

//URL DE ACESSO
$function = "requestActivateCode";

//usado pra criar a canonical
$resPath = "/v1/activateCode";

$url = "https://111.222.333.444/v1/";

$urlCall = $url.$function;

//HTTP HEADERS
$date = gmdate("M, d Y H:i:s \G\M\T", time());
$contentType = "Content-Type: application/json; charset=UTF-8";
$accept = "Accept: application/json";
$xIncommDateTime = substr(substr_replace(date('c'), substr(round(microtime(), 3), 1, 8), 19, 0), 0, -6) . "Z";

//authorization
$type = "application/json; charset=UTF-8";
$canonical = ($xIncommDateTime) + ($type) + ($resPath);

$signature = hash_hmac ('sha1', $key, $canonical);
$idEncoded = base64_encode($id);
$signatureEncoded = base64_encode($signature);
$authorization = "Incomm ". $idEncoded .':'. $signatureEncoded;

$header = array("Date: ".$date, $contentType, $accept, "X-Incomm-DateTime: ".$xIncommDateTime, "Authorization: ".$authorization);


//PARAMS example
$params = array("RetailTransactionRequest" =>
    array(
        "code" => "0000002381237220",
        "amount" => $amount,
        "upc" => $upc,
        "transactionID" => "1234",
        "dateTime" => $xIncommDateTime,
        "retailerName" => $retailerName
    )
);

$request = json_encode($params);


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlCall);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);  
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
//curl_setopt($ch, CURLOPT_SSLVERSION, 1);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
echo curl_setopt($ch, CURLINFO_HEADER_OUT, true); // enable tracking
$result = curl_exec($ch);
echo $result;

$headerSent = curl_getinfo($ch, CURLINFO_HEADER_OUT ); // request headers

echo "<pre>";
print_r($headerSent);
echo "</pre>";

if($result === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
else
{
    echo 'Operation completed without any errors';
    echo "<pre>";
    print_r($result);
    echo "</pre>";
}

And it always returns me: Curl error: Failed to connect to 111.222.333.444 port 443: Connection timed out , what can I do to access correctly ??? Thank you

    
asked by anonymous 01.06.2015 / 01:17

0 answers