Link to home
Start Free TrialLog in
Avatar of suresh pondicherry
suresh pondicherryFlag for United States of America

asked on

SSO API call aborted while sending request

Hi Experts,
Am using vs2013 c#. Am trying to call this method from console to get token from api. Please help me with either suggestions about this error and if possible post me some solution.


 private void GenerateNewToken()
        {  
 string tokk=string.Empty;
 clientSecret = string.Format("{0},{1}", "<username>", this.ClientID);
                      clientSecret += string.Format("{0},{1}", "<password>", this.ClientSecret);
                      Uri baseAddress = new UriBuilder() { Scheme = "https", Host = this.SSOUrl, Port = 443 }.Uri;                  
                     var cookieContainer = new CookieContainer();
                     Cookie clientCookie = new Cookie("client_cookie", this.ClientSecret);
                      clientCookie.Expires = DateTime.Now.AddDays(2);
                     // clientCookie.Domain = Request.Url.Host;
                  //clientCookie.Path = "/"; //?

                    var credentials = new NetworkCredential(this.SystemID, this.SystemPassword);


                      using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer, Credentials = credentials })
                      using (var client = new HttpClient(handler) { BaseAddress = baseAddress })
                      {
                          Uri uri = new UriBuilder() { Scheme = "https", Host = this.SSOUrl }.Uri;
                          var byteArray = new UTF8Encoding().GetBytes(clientSecret);
                          client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

                          FormUrlEncodedContent content = new FormUrlEncodedContent(new[]
                      {
                          new KeyValuePair<string, string>("grant_type", grant_type),
                          new KeyValuePair<string, string>("username", this.SystemID),
                          new KeyValuePair<string, string>("password", this.SystemPassword),
                      });
                         // cookieContainer.Add(baseAddress, clientCookie);
                          var result =  client.PostAsync(uri, content).Result;
JObject accessToken = new JObject(result.Content.ReadAsStringAsync().Result);

 foreach(KeyValuePair<String, JToken> tok in accessToken)
            {
                var tokName = tok.Key;
                tokk = (String)tok.Value["access_token_key"];                
            }
return tokk;
}

Error:
Am getting at  var result =  client.PostAsync(uri, content).Result;
The request was aborted.Could not create SSL/TLS secure channel.


Kind regards,
Pooja
ASKER CERTIFIED SOLUTION
Avatar of Douglas Suyemoto
Douglas Suyemoto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial