GAE,PHP和GCM:无法打开流:HTTP请求失败! HTTP / 1.0 405方法不允许 [英] GAE, PHP and GCM: failed to open stream: HTTP request failed! HTTP/1.0 405 Method Not Allowed
问题描述
我正在开发一个Web应用程序(使用GAE for PHP),通知Android客户端(通过GCM - Google Cloud Messaging) >以下PHP脚本应该可以工作:
$ json = array(
'data'=> array( ...),
'registration_ids'=>数组(...)
);
$ data = json_encode($ json);
$ context = array(
'http'=> array(
'method'=>'post',
'header'=>'Authorization:key = MY_SECRET_KEY'。'\r\\\
。
'Content-Type:application / json'。\r\\\
,
'content'=> $ data
)
);
$ context = @stream_context_create($ context);
$ result = @file_get_contents(https://android.googleapis.com/gcm/send,false,$ context);
上述代码在部署应用程序时正确运行,但不在本地开发环境中运行时。
在本地开发环境 $ result
是 null
和 file_get_contents
echo以下警告未能打开流:HTTP请求失败! HTTP / 1.0 405方法不允许
。
我终于弄清楚发生了什么。 p>
HTTP / 1.0 405方法不允许与'method'=> 'post'
。
相信我,只需将其更改为'method'=> 'POST'
(注意大写!)做了诀窍。
I'm developing a web application (using GAE for PHP) that notifies android clients (via GCM - Google Cloud Messaging) when some content are available for download.
The following PHP script should do job:
$json = array(
'data' => array( ... ),
'registration_ids' => array( ... )
);
$data = json_encode( $json );
$context = array(
'http' => array(
'method' => 'post',
'header' => 'Authorization: key=MY_SECRET_KEY' . "\r\n" .
'Content-Type: application/json' . "\r\n",
'content' => $data
)
);
$context = @stream_context_create($context);
$result = @file_get_contents("https://android.googleapis.com/gcm/send", false, $context);
The above code runs correctly when the app is deployed, but do not when running on my local development environment.
On local development environment $result
is null
and the file_get_contents
"echo" the following warning failed to open stream: HTTP request failed! HTTP/1.0 405 Method Not Allowed
.
I finally figured out what was happening.
The HTTP/1.0 405 Method Not Allowed
was related with the 'method' => 'post'
.
Belive me, simply changing it to 'method' => 'POST'
(note the uppercase!) did the trick.
这篇关于GAE,PHP和GCM:无法打开流:HTTP请求失败! HTTP / 1.0 405方法不允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!