我有以下代码,应该使用Google云消息传递技术将数据从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()
任何想法如何解决这个问题。
问候
胡萨姆
答案 0 :(得分:0)
也许不是
"Authorization:Here_I_Provided_the_Server_API_Key"
你应该试试
"Authorization: key=Here_I_Provided_the_Server_API_Key"
还要确保在应用程序端具有正确的发件人ID,以处理GCM请求。