mercredi 12 septembre 2018

able to get the access token from post master but via code its showing as unauthorized

able to get the access token from post master but via code its showing as unauthorized .. any idea ?`

           client.BaseAddress = new Uri(baseUrl);

            // We want the response to be JSON.
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new 
            MediaTypeWithQualityHeaderValue("application/json"));

            // Build up the data to POST.
            List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();
            postData.Add(new KeyValuePair<string, string>("grant_type",    "client_credentials"));
            postData.Add(new KeyValuePair<string, string>("client_id",     clientId));
            postData.Add(new KeyValuePair<string, string>("client_secret", clientSecret));
            client.DefaultRequestHeaders.Add("Authorization", "Basic xxxxxxx");
            FormUrlEncodedContent content = new FormUrlEncodedContent(postData);
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            // Post to the Server and parse the response.
            HttpResponseMessage response = await client.PostAsync("Token", content);
            string jsonString            = await response.Content.ReadAsStringAsync();
            object responseData          = JsonConvert.DeserializeObject(jsonString);

            // return the Access Token.
            return ((dynamic)responseData).access_token;` 




Aucun commentaire:

Enregistrer un commentaire