title: Sending data to GCM Android application over .NET
body: <p>Im sending data from my .NET application to GCM trough a POST.
  1st my android device gets an Id, which it POST to my ASP.NET application.
  then i have a simple button on my website "Send a message" , this posts data to GCM in a JSON format.</p>
  
  <pre><code>Private Function SendNotification(ByVal JSonData As String) As String
      ServicePointManager.ServerCertificateValidationCallback = Function(sender As       Object,         certificate As X509Certificate, chain As X509Chain, sslPolicyErrors As SslPolicyErrors) True
      '/// Creating POST.
      Dim request As WebRequest = WebRequest.Create("https://android.googleapis.com/gcm/send")
      request.Method = "POST"
      request.ContentType = "Content-Type: application/json"
      request.Headers.Add(String.Format("Authorization: key={0}", MyAPIKey))
  
      '/// Converting data to byte array.
      Dim postData As String = JSonData
      Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
  
      '/// Post
      request.ContentLength = byteArray.Length
      Dim dataStream As Stream = request.GetRequestStream()
      dataStream.Write(byteArray, 0, byteArray.Length)
      dataStream.Close()
  
      '/// Response
      Dim response As WebResponse = request.GetResponse()
      dataStream = response.GetResponseStream()
      Dim reader As New StreamReader(dataStream)
      Dim responseFromServer As String = reader.ReadToEnd()
  
      reader.Close()
      dataStream.Close()
      response.Close()
  
      Return responseFromServer
  End Function
  </code></pre>
  
  <p>JsonData byval contains :</p>
  
  <pre><code>{ "collapse_key":"DitIsEenUniekeIdentifier",
    "time_to_live":108,
    "delay_while_idle":true,
    "data": {
      "MessageId":1,
      "TestInformation":"BlieBloeBlaaaa tadaaa!"
     },
     "registration_ids":["APA91bFYQbSDzQDsoRrR3bnKtH_o72kQ7oiArg79WNz8qeCVoe6Kxu_BdcVftX1pGOfwLCLZbf_D3b7-V2yIaVasHxWXbn35nJO1bIiDzF84ifCHKJTyK3KiZmHZwAJliVIFcZFEVEsKTRiXWgpm9WWmnPrsbKvASy6FZyv4Eyfv-K526Q38Hjs"]
     }"
  </code></pre>
  
  <p>Which seems to be correct when i check google dev pages.
  <a href="http://developer.android.com/google/gcm/gcm.html" rel="nofollow">http://developer.android.com/google/gcm/gcm.html</a></p>
  
  <p>I was able before to send to GCM with the same function except i was using plain text then.
  This is the first time trying the Json.
  I changed the header of the post.
        request.ContentType = "Content-Type: application/json"
  Which was before
        request.ContentType = "application/x-www-form-urlencoded"</p>
  
  <p>The data i was sending in plain text : </p>
  
  <pre><code>Dim postData As String = String.Format("registration_id={0}&amp;data.payload={1}&amp;collapse_key={2}", ReceiverKey, Message, collaspeKey)
  </code></pre>
  
  <p>The error message im getting from GCM : MissingRegistration
  According to google :</p>
  
  <p>Registration ID</p>
  
  <p>Check that the request contains a registration ID (either in the registration_id parameter in a plain text message, or in the registration_ids field in JSON). 
  Happens when error code is MissingRegistration.</p>
  
  <p>Anny help is greatly appreciated.</p>
  
  <p>Kind Regards.</p>