Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用GCM和ASP.net发送数据_Android_Asp.net_Vb.net - Fatal编程技术网

Android 使用GCM和ASP.net发送数据

Android 使用GCM和ASP.net发送数据,android,asp.net,vb.net,Android,Asp.net,Vb.net,我有下面的代码,它应该使用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("htt

我有下面的代码,它应该使用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()
你知道我该如何解决这个问题吗

问候

Husam

可能代替

"Authorization:Here_I_Provided_the_Server_API_Key"
你应该试试

"Authorization: key=Here_I_Provided_the_Server_API_Key"

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

我还按照Demonick的建议为我的请求添加了另一个标题:request.Headers.Add(“发件人:ID=我的\u项目的\u ID”)。我还将Dim postdata更改为String=regID+TextBox1.Text+collapsKey,将以下Dim postdata更改为String=“registration\u id=“+regID+”&data.message=“+TextBox1.Text+”&collapsKey=“+collapsKey