One Service
One Service

Reputation: 31

Error:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

I am trying to make an HTTPS request using cURL in PHP 5.6 (i am forced to use 5.6 due enviroment), but I keep encountering the following error:

error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

<?php
// The endpoint URL
$url = "https://url.com";

// The headers
$headers = array(
    'Authorization: Basic bm9zOm5vcw==',
    'Content-Type: application/json'
);

// The request payload
$data = array(
    "properties" => array(
        "downData.cmCER", "downData.rxPwr", "downData.snr", 
        "regStatusCode", "cmResetCnt", "upData.cmCER", 
        "upData.snr", "upData.txPwr"
    ),
    "startts" => "2024-10-10T11:49:30.936Z",
    "endts" => "2024-10-17T11:49:30.936Z",
    "deviceId" => array("111111111")
);

// Initialize the cURL session
$ch = curl_init();

// Set the cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Insecure, ignores SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Insecure, ignores SSL verification
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

// Execute the cURL request
$response = curl_exec($ch);

// Check for errors
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    // Output the response
    echo $response;
}

// Close the cURL session
curl_close($ch);
?>

When i try to run it direcly via curl, it works:

curl --location --insecure -X POST "https://url.com" --header "Authorization: Basic bm9zOm5vcw==" --header "Content-Type: application/json" --data "{\"properties\": [\"downData.cmCER\", \"downData.rxPwr\", \"downData.snr\", \"regStatusCode\", \"cmResetCnt\", \"upData.cmCER\", \"upData.snr\", \"upData.txPwr\"], \"startts\": \"2024-10-10T11:49:30.936Z\", \"endts\": \"2024-10-17T11:49:30.936Z\", \"deviceId\": [\"1111111111\"]}"

Upvotes: 0

Views: 24

Answers (1)

One Service
One Service

Reputation: 31

$curlCommand = "curl --location --insecure.."    
$response = shell_exec($curlCommand);

This solved my issue!

Upvotes: 1

Related Questions