GAE, PHP and GCM: failed to open stream: HTTP request failed! HTTP/1.0 405 Method Not Allowed

ε祈祈猫儿з 提交于 2020-01-02 05:20:49

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/20567824/gae-php-and-gcm-failed-to-open-stream-http-request-failed-http-1-0-405-metho

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!