错误:错误:140770FC:SSL例程:SSL23_GET_SERVER_HELLO:未知协议

问题描述 投票:0回答:1

我尝试在 PHP 5.6 中使用 cURL 发出 HTTPS 请求(由于环境原因,我被迫使用 5.6),但我一直遇到以下错误:

错误:140770FC:SSL例程:SSL23_GET_SERVER_HELLO:未知协议

<?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);
?>

当我尝试通过curl直接运行它时,它起作用了:

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\"]}"
php php-curl
1个回答
0
投票
$curlCommand = "curl --location --insecure.."    
$response = shell_exec($curlCommand);

这解决了我的问题!

© www.soinside.com 2019 - 2024. All rights reserved.