Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
720 views
in Technique[技术] by (71.8m points)

android - GCM Implementation using PHP always facing Unauthorized Error 401

I am always getting 401 error.Please any one could let me know exactly what should be HTTP referrers if i am using my local server. i.e Currently I am using:

    http://localhost/GCM/index.php 

and generating a API access key using it.

Here is my php code for GCM request.

                $key='mykey';
                $headers=array('Contenttype:application/json','Authorization:key='.$key);
                $url = 'https://android.googleapis.com/gcm/send';
                $ch = curl_init();
                $curlConfig = array(
                CURLOPT_URL            => $url,
                CURLOPT_POST           => true,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_POSTFIELDS     => json_encode(array('field1' => 'some date','field2' => 'some other data',)),
                CURLOPT_HTTPHEADER     => $headers,
                CURLOPT_SSL_VERIFYPEER => false,
                CURLOPT_SSL_VERIFYHOST => false,
                );
                curl_setopt_array($ch, $curlConfig);
                $result = curl_exec($ch);
                curl_close($ch);
                if($result==FALSE){
                    echo curl_error($ch);
                    echo curl_getinfo($ch);
                }else{
                    echo $result;
                }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...