向GCM服务器发出curl请求时收到错误:
JSON_PARSING_ERROR: Unexpected character (m) at position 0
curl
请求:
curl -i -H "Content-Type: application/json" -H "Authorization: key=AIzaSyAuKLBnVEv_bm4fp88RqKaVm8DClzc"
-X POST -d "message":"Hi I am Developer","registration_ids":"["APA91bGj-wkz4m6tEaFfual2HuRHNAn3CmAE6nRmv5LaOnuWa_6D3AnacqTmSCHXiKvdzINVc_XUGJhrXk0z5hQomdCM_9Nf6QqB-Pf9Q6Tf_DraUZZaUVtDiaRaIStgXsx0zMFqKJHU0q75OGCtq5OSGR11l3mCB5DBtzvl4nFwOws_UuA"]"
https://android.googleapis.com/gcm/send
答案 0 :(得分:2)
我对GCM API一无所知,但我看到了错误。您没有发送有效的JSON字符串,服务器无法解析它。
用大括号包裹你的数据。取代
-d "message":"Hi I am Developer","registration_ids":"["APA91bGj-wkz4m6tEaFfual2HuRHNAn3CmAE6nRmv5LaOnuWa_6D3AnacqTmSCHXiKvdzINVc_XUGJhrXk0z5hQomdCM_9Nf6QqB-Pf9Q6Tf_DraUZZaUVtDiaRaIStgXsx0zMFqKJHU0q75OGCtq5OSGR11l3mCB5DBtzvl4nFwOws_UuA"]"
与
-d '{"message":"Hi I am Developer","registration_ids":"["APA91bGj-wkz4m6tEaFfual2HuRHNAn3CmAE6nRmv5LaOnuWa_6D3AnacqTmSCHXiKvdzINVc_XUGJhrXk0z5hQomdCM_9Nf6QqB-Pf9Q6Tf_DraUZZaUVtDiaRaIStgXsx0zMFqKJHU0q75OGCtq5OSGR11l3mCB5DBtzvl4nFwOws_UuA"]"}'