【问题标题】:Curl:Unknown SSL protocol error gcm卷曲:未知的 SSL 协议错误 gcm
【发布时间】:2016-02-06 06:34:15
【问题描述】:

enter image description here我用php(MAMP)设计了gcm服务器。 curl version-7.43.0,php version 7.0.0 .server的代码-

<?php



function send_push_notification($registration_id,$message){
    define('API_KEY','AIzaSyAoFih8qEFlOis3vVWhsxxlLxxxxxxxxxx');
    $url='https://gcm-http.googleapis.com/gcm/send';

    $fields=array(
        'registration_id'=>$registration_id,
        'data'=>$message,
        );
    $headers=array(
        'Authorization:key='.API_KEY,
        'Content-Type:application/json'
        );

    $ch=curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSLVERSION, 3);



  $result = curl_exec($ch);
        if ($result === FALSE) {
            die('Curl failed: ' . curl_error($ch));
        }

        // Close connection
        curl_close($ch);
        echo $result;
 }



?>
<?php
send_push_notification("e2DgrsZPGKU:APA91bF_73a6-o5CLV-gdcZzYFAbtikJqi-5w6gDSCaRa4z8-1iGLeV5SS6hQkW8pj_g_DxBe7JLDsOPMGu3y1GkKw1vpn_ZEWIeCwbSITpd0pLwaz50W8uzHKNghvnf1xxxxxxxxxxx","hi");
?>

当我尝试在浏览器中运行这个 php 脚本时,它显示以下错误

Curl 失败:连接到未知 SSL 协议错误 gcm-http.googleapis.com:443

我已禁用 SSL 验证,但仍然显示 curl 错误。

【问题讨论】:

  • 这不是对等名称或证书问题,而是协议错误。如果您删除 curl_setopt($ch, CURLOPT_SSLVERSION, 3); 并让 cURL 选择怎么办?无论如何,TLS 更好(更安全)。
  • 我在阅读本网站上的一个答案后添加了curl_setopt($ch, CURLOPT_SSLVERSION, 3);。删除它后没有任何区别。仍然是同样的错误。
  • 通常没有理由设置 SSL 版本 - 让服务器和客户端选择最佳协议和密码。添加这可能会有所帮助:curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_STDERR, fopen('php://output', 'w+')); 它应该从 cURL 打印额外的调试输出,可能会提供有关协议错误的更多细节。
  • 可能是this 错误/问题。详细输出可能会显示更相关和更有用的消息,但最后一个 unknown ssl protocol error 是您看到的 SSLv3 或 TLS 和 RC4(两者均支持 GCM)。
  • 上面的代码没有打印出额外的错误信息。php_error.log中也没有错误。浏览器只显示Curl failed: Unknown SSL protocol error in connection to gcm-http.googleapis.com:443 .每次我尝试运行它。

标签: php android ssl curl google-cloud-messaging


【解决方案1】:

将 SSL 版本更改为 6 对我有用。

curl_setopt($ch,CURLOPT_SSLVERSION,6);

【讨论】:

    猜你喜欢
    • 2014-03-04
    • 1970-01-01
    • 2014-11-24
    • 2013-12-27
    • 2017-01-20
    • 2017-12-22
    • 2014-12-16
    • 2017-10-02
    相关资源
    最近更新 更多