API access on port 443 returning Connection timed out

Asked

Viewed 1,078 times

0

I’m setting up a webAPI and after configuring everything (id, key, Signature, other data the api asks for) and authenticate by HEADER in php using json and CURL to post on 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 always returns to 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

  • UP: on production server the error is different Not Found&#xA;The server has not found anything matching the request URI&#xA;You can get technical details here.&#xA;Please continue your visit at our home page.

  • 111.222.333.444 is it an IP or a name? I believe you have hidden it for security reasons, but please be clearer. On the test server, is HTTPS properly configured? Running netstat -l door 443 appears as listening? On the production server, the command ping 111.222.333.444 can find the host?

  • thanks for the help, so the command netstat -l that results me imagem. I saw no reference to port 443.... but as it is a webserver released only pro ip production even within the Prod server. Ubuntu using ping it does not find the host and only fail. The problem is the same port 443?? The site uses https:// and openssl-1.0

  • In the image, the port 443 is open (he listed the protocol instead of the port name, because it is a known port), but only with the bind in Ipv6, and not in Ipv4. This may be the problem. On the production server, the problem is more complicated because I do not know the topology of your network. I recommend that you contact the network administrator.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.