I'm not sure what's happening. Able to get access token by making it sync request from local.
public string GetAccessToken(string authorizationCode)
{
var inputParams = new Dictionary<string, string>
{
{ "grant_type", "authorization_code" },
{ "code", authorizationCode },
{ "redirect_uri", "http://localhost:1938/Account/LinkedinOauthCallback" },
{ "client_id", _linkedInSettings.AppKey },
{ "client_secret", _linkedInSettings.AppSecret }
};
var content = new FormUrlEncodedContent(inputParams);
content.Headers.Clear();
content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string accessToken = "";
using (HttpClient client = new HttpClient())
{
//client.DefaultRequestHeaders.Accept.Clear();
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
HttpResponseMessage response = await client.PostAsync("https://www.linkedin.com/oauth/v2/accessToken", content).Result;
var accessTokenResponse = await response.Content.ReadAsAsync<LinkedInAccessTokenResponse>().Result;
accessToken = accessTokenResponse.access_token;
}
return accessToken;
}
But now getting error on server:
System.Net.Http.HttpRequestException:
An error occurred while sending the request. --->
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. --->
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. --->
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
Posted On:
07-Jan-2021 07:14