suresh pondicherry
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.Sys temID, 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(cl ientSecret );
client.DefaultRequestHeade rs.Authori zation = new AuthenticationHeaderValue( "Basic", Convert.ToBase64String(byt eArray));
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(baseAd dress, clientCookie);
var result = client.PostAsync(uri, content).Result;
JObject accessToken = new JObject(result.Content.Rea dAsStringA sync().Res ult);
foreach(KeyValuePair<Strin g, 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
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.Sys
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(cl
client.DefaultRequestHeade
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(baseAd
var result = client.PostAsync(uri, content).Result;
JObject accessToken = new JObject(result.Content.Rea
foreach(KeyValuePair<Strin
{
var tokName = tok.Key;
tokk = (String)tok.Value["access_
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.