收到ID和身份验证令牌后发送邮件时出现c2dm 401错误

Dix*_*ine 8 java android android-c2dm

虽然有些问题被接受,但我看到了许多类似的问题,但没有很好的答案.我已注册C2DM.我收到了确认邮件.然后我写了一些简单的应用程序来注册C2DM.我得到了id(在模拟器和真实设备上试过).然后我获得了我用于C2DM注册的电子邮件的auth令牌(带卷曲)(我在app中用来获取id的电子邮件).
当我尝试执行推送(也使用curl)时,我收到401错误(就像auth令牌错误一样).

我阅读了很多教程,但我的想法已经不多了.

Chr*_*ipp 1

让我尝试一下(仅使用curl):

首先我们申请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

在结果中,您收到了身份验证令牌:

< 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):

请注意,结果中的 Auth 响应首字母大写:“Auth=XXX”!

现在我们将结果用于下一个请求,但首字母小写:
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

这有效!但是,如果您使用第一个响应中的身份验证(“Auth”中的大写 A),您会收到 401 错误:

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

所以请求 2 的“auth”是区分大小写的。我认为这是 50% 的用户正在陷入的陷阱。希望有帮助。