1

我有以下代码应该使用 Google Cloud Messaging Technology 将数据从在 asp.net (VB.Net) 中开发的 Web 应用程序发送到 android 设备,但我不断收到此错误:远程服务器返回错误:(401) 未经授权。

代码如下:

Dim regID As String = "REG_ID_ that i got when I developed the Clint side of this technology"
Dim request As WebRequest = WebRequest.Create("https://android.googleapis.com/gcm/send")
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
request.Headers.Add("Authorization:Here_I_Provided_the_Server_API_Key")
Dim collapsKey = Guid.NewGuid.ToString("N")
Dim postdata As String = regID + TextBox1.Text + collapsKey
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postdata)
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim resposne As WebResponse = request.GetResponse
Dim dataresponse As Stream = resposne.GetResponseStream
Dim reader As New StreamReader(dataresponse)
Dim sResponseFromServer As String = reader.ReadToEnd
Label1.Text = sResponseFromServer
reader.Close()
dataresponse.Close()
resposne.Close()

任何想法我该如何解决这个问题。

问候

胡萨姆

4

1 回答 1

0

也许代替

"Authorization:Here_I_Provided_the_Server_API_Key"

你应该试试

"Authorization: key=Here_I_Provided_the_Server_API_Key"

还要确保您在处理 GCM 请求的应用程序端具有正确的发件人 ID。

于 2012-11-11T12:21:37.547 回答