【问题标题】:Unable to post data to the remote server due to incompatible OpenSSL versions between remote server and local work-station由于远程服务器和本地工作站之间的 OpenSSL 版本不兼容,无法将数据发布到远程服务器
【发布时间】:2020-08-28 12:30:51
【问题描述】:

我需要找到另一种解决方案,通过 PHP curl 将数据发布到远程服务器,而无需将当前的 PHP 版本 5.4.9 更新到 7 或更高版本,只是为了解决 OpenSSL 不兼容问题。

本地服务器

  • 操作系统:Windows 7,32 位架构
  • PHP版本:5.4.9
  • OpenSSL 版本:0.9.8x

远程服务器(https)

  • PHP版本:7.2.27
  • OpenSSL 版本:1.0.2k

这是我的 PHP 代码

<?php

$url = "https://****/api/daily/sales";
$headers = array(
    'AUTH-TOKEN: *****',
    'CONTENT-TYPE: application/json'
);

$items = array(
    'customer_no'=>'001',
    'customer_name'=>'John Smith',
    'customer_address'=>'Bohol Philippines',
    'customer_province'=>'Bohol',
    'customer_city'=>'Tagbilaran',
    'salesman_no'=>'001',
    'salesman_name'=>'Salesman A',
    'salesman_mobile_no'=>'0912345678',
    'supervisor_id'=>'001',
    'supervisor_name'=>'Supervisor A',
    'item_no'=>'001',
    'item_description'=>'Detergent',
    'qty'=>2,
    'price'=>5,
    'uom'=>'pcs',
    'sales_value'=>'10',
    'currency'=>'PHP'
);
    $data = array(
        'invoice_date'=>'2020-05-01',
        'items'=>array($items),
    );

echo post($data, $url, $headers);


function post($data,$url,$headers)
    {
        $payload = json_encode($data);
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $result = curl_exec($ch);
        $curl_errno = curl_errno($ch);
        curl_close($ch);
        return $result;
    }

?>

C:\Users\ronvi\Projects\PHP> php index.php

通过 PHP curl 发布时返回的错误

* About to connect() to (my website) port 443 (#0)
*   Trying (my web server IP address)...
* connected
* Connected to (my domain name) (my web server IP address) port 443 (#0)
* error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
* Closing connection #0

非常感谢您的建议或想法。

谢谢,

罗恩

【问题讨论】:

  • PHP 5.4.9 和 OpenSSL 0.9.8x 都已经过时了。与 Windows 7 一样。您需要升级。你投入的时间越多,试图绕过这个事实就是浪费时间。同样,您的问题并不完全是主题,因为您甚至没有显示您的 PHP 代码,所以没有人知道您如何处理 TLS 握手、您使用什么库等等......
  • ^^ 帕特里克所说的。您在本地计算机上的整个技术堆栈已过时且不受支持。现在是时候升级所有这些了。为什么要避免这样做?
  • 帕特里克·梅夫泽克和艾迪森。服务器的客户端或所有者不允许我升级他们当前的操作系统甚至安装其他应用程序。
  • 我没有权限在本地服务器设置上进行升级,但我在远程服务器上是我们的 Web 服务器。
  • 我只需要将数据从本地发布到我们的远程服务器就可以了。

标签: php ssl web https openssl


【解决方案1】:

我通过使用 curl for windows 作为带有 h​​ttps/http 的数据发送方解决了这个问题。

我从官网https://curl.haxx.se/windows/下载了二进制文件,在本地机器某处解压,并将二进制目录添加到环境变量中,并更新了PHP代码,见下文。

<?php

$items = array(
    'customer_no'=>'001',
    'customer_name'=>'John Smith',
    'customer_address'=>'Bohol Philippines',
    'customer_province'=>'Bohol',
    'customer_city'=>'Tagbilaran',
    'salesman_no'=>'001',
    'salesman_name'=>'Salesman A',
    'salesman_mobile_no'=>'0912345678',
    'supervisor_id'=>'001',
    'supervisor_name'=>'Supervisor A',
    'item_no'=>'001',
    'item_description'=>'Detergent',
    'qty'=>2,
    'price'=>5,
    'uom'=>'pcs',
    'sales_value'=>'10',
    'currency'=>'PHP'
);
    $data = array(
        'invoice_date'=>'2020-05-01',
        'items'=>array($items),
    );

$json = json_encode($data);
$json = str_replace('"', '\"', $json); // using ' to wrap json data is not working in windows
$curl = "curl -X POST -H \"Content-Type: application/json\" -H \"AUTH-TOKEN: ******\" https://****.com.ph/api/daily/sales --data \"".$json."\" "; // CURL command
exec($curl,$response); // execute CURL command
print_r($response); // print array response

?>

令人惊讶的是,CURL 版本 7.70.0 可以完美地在 Windows 7 等 32 位架构的旧操作系统上运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-28
    相关资源
    最近更新 更多