Ejemplo n.º 1
0
 private static async Task SetDataAsync(HttpWebRequest request, Object data, String contentType)
 {
     if (data != null)
     {
         String dataString;
         if (data is Hashtable)
         {
             dataString = JSON.JsonEncode(data);
         }
         else
         {
             dataString = data.ToString();
         }
         if (dataString.Length > 0)
         {
             using (Stream requestStream = await request.GetRequestStreamAsync())
             {
                 using (StreamWriter writer = new StreamWriter(requestStream))
                 {
                     writer.Write(dataString);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        public async Task <String> GetAccessTokenAsync()
        {
            if (this.ll_access_token != null)
            {
                return(this.ll_access_token);
            }

            Dictionary <String, String> appClientValues = new Dictionary <String, String>
            {
                { "grant_type", "client_credentials" },
                { "client_id", this.client_id },
                { "client_secret", this.client_secret }
            };

            String appClientValuesQuery = this.BuildQuery(appClientValues);

            Hashtable access_data = await RestClient.PostAsync("/oauth/token", appClientValuesQuery, RestClient.MIME_FORM);

            if (((int)access_data["status"]) == 200)
            {
                this.access_data = (Hashtable)access_data["response"];
                return((String)this.access_data["access_token"]);
            }
            else
            {
                throw new Exception(JSON.JsonEncode(access_data));
            }
        }