Sivakumar

Sivakumar

  • NA
  • 551
  • 217.4k

Access token shows a null after calling other API

Sep 16 2015 5:31 AM
Hi,
 
This is my code :
 
var login = new LoginData() { Email = email, Password = password };

var response = await client.PostAsJsonAsync(URI, login);
var token = response.Content.ReadAsAsync<TokenResponse>(new[] { new JsonMediaTypeFormatter() }).Result;

client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);

if (response.IsSuccessStatusCode)
{

var productJsonString = await response.Content.ReadAsStringAsync();
LoginData loginObj = JsonConvert.DeserializeObject<LoginData>(productJsonString);
Body_textBox.Text = productJsonString;
 
first time login its generate a access token but calling different api is shows null.
 
uri like this : http://localhost:54075/api/members/login
 
http://localhost:54075/api/teams/teamid/?teamid=1
 
first uri works fine. but second uri shows access token values is null.