ios - Ionic push notification api in c# -


so based on tom raz post ionic push notification api in c# webapi. tried implement method send push notification using ionic push notifications api here code:

    public void sendtoionic(string regid, string msg) {          using (var client = new httpclient())         {             string data = "{ \"user_ids\":[\" "+ regid + "\"],\"notification\":{\"alert\":\" "+ msg + "\"}}";              string json = newtonsoft.json.jsonconvert.serializeobject(data);              client.baseaddress = new uri("https://push.ionic.io/api/v1/push");             client.defaultrequestheaders.accept.clear();             client.defaultrequestheaders.add("x-ionic-application-id", "1d74b1f2");             var keybase64 = "basic %s" + "53a03dc7d9ce58511263e40580294f62af36b89be7cc4db2";             client.defaultrequestheaders.add("authorization", keybase64);             httprequestmessage request = new httprequestmessage(httpmethod.post, "https://push.ionic.io/api/v1/push");              request.content = new stringcontent(data, encoding.utf8, "application/json");             var response = client.sendasync(request).result;         }      } 

but keep getting response error 403 forbidden;. complete response:

{statuscode: 403, reasonphrase: 'forbidden', version: 1.1, content: system.net.http.streamcontent, headers: { connection: keep-alive access-control-allow-origin: * access-control-allow-headers: origin, x-requested-with, content-type, accept date: fri, 15 jan 2016 20:50:33 gmt etag: w/"35-nglzv/ec8cys+kjzq1p9rg" server: cowboy via: 1.1 vegur x-powered-by: express content-length: 53 content-type: application/json; charset=utf-8 }}

not sure wrong. stuck. appreciated.

var keybase64 = "basic %s" + "..." 

%s concatenate in python. need convert base64

you can use

client.defaultrequestheaders.add("x-ionic-application-id", "1d74b1f2"); var ionic_private_key_base_64 = system.convert.tobase64string(system.text.encoding.utf8.getbytes("53a03dc7d9ce58511263e40580294f62af36b89be7cc4db2:")); // ends 2 points var keybase64 = "basic " + ionic_private_key_base_64 ; client.defaultrequestheaders.add("authorization", keybase64); 

http://docs.ionic.io/docs/push-sending-push#section-authenticating-your-requests


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -