1

I am using GMC to send a message to an Android phone from C#.

link: https://android.googleapis.com/gcm/send

Method: POST

Header:

Authorization: key=AIzaSyCPNaU7Pn6csAKxXQHJXSprwWjO0JWaFsw

Body:

{
    "registration_ids": [
        "APA91bEzrLAiphAldxy6lSpSO503YaNm7CCng5uLzGRFWw93dwQIKfisdioyTY2Y0AyJrV81DHd8afBvmOi_KWgMcQKLFwCXJR8vLzuu2_nijBBu9kXRmcBDAGdwTMq9PQ5QPRWDcHh3PGFViTs4lC2DysiRLykASvV25ivY7Vwl_EvNZgcnqkmDM"
    ],
    "data": {
        "price": "Nguyễn Anh Quế. hehe"
    }
}

I have tried it from web with success but in C# I don't know how to do it.

4

2 回答 2

0

像这样:

string postData = "{ \"registration_ids\": [ \"APA91bEzrLAiphAldxy6lSpSO503YaNm7CCng5uLzGRFWw93dwQIKfisdioyTY2Y0AyJrV81DHd8afBvmOi_KWgMcQKLFwCXJR8vLzuu2_nijBBu9kXRmcBDAGdwTMq9PQ5QPRWDcHh3PGFViTs4lC2DysiRLykASvV25ivY7Vwl_EvNZgcnqkmDM\" ], \"data\": { \"price\": \"Nguyễn Anh Quế. hehe\" } }";

var request = (HttpWebClient)WebClient.Request("https://android.googleapis.com/gcm/send");
request.Method="POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream ();
dataStream.Write (byteArray, 0, byteArray.Length);
dataStream.Close ();
var response = (HttpWebRequest)request.GetResponse ();
// response contains the response
于 2013-04-12T16:56:07.303 回答
0
string postData = "{ \"registration_ids\": [ \"APA91bEzrLAiphAldxy6lSpSO503YaNm7CCng5uLzGRFWw93dwQIKfisdioyTY2Y0AyJrV81DHd8afBvmOi_KWgMcQKLFwCXJR8vLzuu2_nijBBu9kXRmcBDAGdwTMq9PQ5QPRWDcHh3PGFViTs4lC2DysiRLykASvV25ivY7Vwl_EvNZgcnqkmDM\" ], \"data\": { \"price\": \"Nguyễn Anh Quế. hehe\" } }";

        var request = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send");
        request.Method = "POST";
        request.Headers.Add("Authorization: key=AIzaSyCPNaU7Pn6csAKxXQHJXSprwWjO0JWaFsw");
        request.ContentType = "application/json";
        byte[] byteArray = Encoding.UTF8.GetBytes(postData);
        request.ContentLength = byteArray.Length;
        Stream dataStream = request.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();
        var response = request.GetResponse();
于 2013-04-13T04:30:38.790 回答