Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MAIN METHOD
- public void GetTags (string applicationCode, string HWID, Action <string> callback)
- {
- const string applicationProperty = "application";
- const string hwidProperty = "hwid";
- JObject json = new JObject (new JProperty (applicationProperty, applicationCode), new JProperty (hwidProperty, HWID));
- const string getTagsAction = "getTags";
- CallUri (getTagsAction, json, callback);
- }
- private void CallUri (string action, JObject data, Action <string> callback)
- {
- string uriString = string.Format ("https://cp.pushwoosh.com/json/1.3/{0}", action);
- Uri url = new Uri (uriString);
- const string requestProperty = "request";
- JObject json = new JObject (new JProperty (requestProperty, data));
- DoPostRequest (url, json, callback);
- }
- private void DoPostRequest (Uri url, JObject data, Action <string> callback)
- {
- HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create (url);
- req.ContentType = "text/json";
- req.Method = "POST";
- using (var streamWriter = new StreamWriter (req.GetRequestStream ())) {
- streamWriter.Write (data.ToString ());
- }
- HttpWebResponse httpResponse;
- try {
- httpResponse = (HttpWebResponse) req.GetResponse ();
- }
- catch (Exception exc) {
- throw new Exception (string.Format ("Problem with {0}, {1}", url, exc.Message));
- }
- using (var streamReader = new StreamReader (httpResponse.GetResponseStream ())) {
- var responseText = streamReader.ReadToEnd ();
- callback (responseText);
- Debug.LogFormat ("responseText: {0}", responseText);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement