【问题标题】:Google doesnt work on https but it work on http谷歌在 https 上不工作,但在 http 上工作
【发布时间】:2013-08-18 18:37:01
【问题描述】:

我正在使用 google 的 api 发送推送通知,问题是如果我使用“http://android.googleapis.com/gcm/send”它会完美,但如果我使用 “https://android.googleapis.com/gcm/send”(http 上带有 S)它不起作用并且 curl 停止。

有人知道为什么吗?

$headers = array('Authorization:key=' . $apiKey);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 
"http://android.googleapis.com/gcm/send");
if ($headers)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

【问题讨论】:

  • It doesnt work and the curl stop. 1/ 怎么不工作?问题/错误是什么? 2/ CURL 是如何停止的?
  • echo "这是可见的"; $response = curl_exec($ch); echo "这是不可见的";当我使用https时,它只显示“这是可见的”,仅此而已,当我使用http时,它显示两个文本
  • 要么打开错误报告,要么查看错误日志以查看问题。

标签: php http curl https google-cloud-messaging


【解决方案1】:

我在这两种情况下都得到了回应:

<?php
ini_set('display_errors', true);
error_reporting(-1);

function o($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization:key=123']);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, [1,2,3]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

var_dump( o("http://android.googleapis.com/gcm/send") );
var_dump( o("https://android.googleapis.com/gcm/send") );

所以你可能在某个地方有错误。

【讨论】:

  • 你有什么错误吗?在文件的开头写ini_set('display_errors', true); error_reporting(-1);,如果有错误请报告给我们。
  • 我得到的唯一错误是变量为空,但仍然只有 1 个响应
  • 如果您将我的代码保存在some.php 文件中并运行它,您仍然会出错吗?
  • @D4rWiNS :出了什么问题?
  • 我们仍然不知道我是否在家中使用该脚本,但如果我在工作中使用它,它就不起作用,所以它似乎是我告诉我的服务器配置中的东西老板,他给我们的服务器经理发了一张票
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-26
  • 2012-03-20
  • 2020-02-18
  • 1970-01-01
  • 2020-11-29
  • 1970-01-01
相关资源
最近更新 更多