I have 2 servers for production and developement. My developement server
running in HTTP protocol and production in HTTPS.
In production I have self signed Certificate. All my php files running is
fine. Now I have a php file send GCM notification to Android device which
is working fine in non SSL developement server but same code is not working
over SSL production server. I got 401 error. I added my production server
IP in the whitelist but still not working.

The php code is given below which is working fine in developement.


class GCM {

     //put your code here
     // constructor
     function __construct() {
           // echo("GCM Called!");
          * Sending Push Notification
     public function send_push_notification($registatoin_id, $message,
$phone) {

             // Set POST variables
              $url = 'https://android.googleapis.com/gcm/send';


             $fields = array(
                 'registration_ids' => $registatoin_ids,
                 'data' => array("message"=>$message,"phone"=>$phone),

             $headers = array(
                 'Authorization: key=' . $GOOGLE_API_KEY,
                 'Content-Type: application/json'

             $field_string = '';

             foreach($fields as $key=>$value){
             $field_string .=$key.'='.$value.'&';

             // Open connection
             $ch = curl_init();

             // Set the url, number of POST vars, POST data
             curl_setopt($ch, CURLOPT_URL, $url);

             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

             // Disabling SSL Certificate support temporarly
          // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

             curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);

             curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
             // Execute post
             $result = curl_exec($ch);
             if ($result === FALSE) {
                 die('Curl failed: ' . curl_error($ch));

             // Close connection
           // echo $result;

Kindly help me to solve this issue.

You received this message because you are subscribed to the Google Groups "android-gcm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-gcm+unsubscribe@googlegroups.com.
To post to this group, send email to android-gcm@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-gcm/c2c8027b-82e8-4934-8865-fc5ec932f982%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupandroid-gcm @
postedApr 29, '14 at 9:46p
activeApr 29, '14 at 9:46p

1 user in discussion

Tapas M: 1 post



site design / logo © 2019 Grokbase