c2dm 401 error when sending messages after receiving id and auth token

前端 未结 2 1336
离开以前
离开以前 2021-01-02 10:23

I have seen many similiar questions but no good answer despite some of them being accepted. I have registered for C2DM. I received confirmation email. Then I wrote some sim

2条回答
  •  庸人自扰
    2021-01-02 10:59

    Let me try it (with curl only):

    At first we are applying for the auth token:

    curl.exe -v -k https://www.google.com/accounts/ClientLogin -d Email=xyz@gmail.com -d Passwd=secret -d accountType=GOOGLE -d source=your.registered.domain -d service=ac2dm

    In the result your are receiving the auth token:

    < HTTP/1.1 200 OK
    SID=XXX
    LSID=XXX
    Auth=XXX
    * Connection #0 to host www.google.com left intact
    * Closing connection #0
    * SSLv3, TLS alert, Client hello (1):

    Please note that the Auth response is in the result with an uppercase first letter: "Auth=XXX"!

    Now we are using the result for the next request but with lowercase first letter:
    curl.exe -v -k --header "Authorization: GoogleLogin auth=XXX" https://android.apis.google.com/c2dm/send -d "registration_id=XXX" -d "data=helloooo" -d collapse_key=Z

    And this works! But you are getting a 401 error, if you are using the auth like in the first response (upper case A in "Auth"):

    curl.exe" -v -k --header "Authorization: GoogleLogin Auth=XXX" https://android.apis.google.com/c2dm/send -d "registration_id=XXX" -d "data=helloooo" -d collapse_key=Z

    So the "auth" of request 2 is case sensitive. I think this is a pitfall 50% of the users are stepping into. Hope that helps.

提交回复
热议问题