Sivakumar

Sivakumar

  • NA
  • 551
  • 218.4k

How to send the request using access token in web api

Sep 15 2015 6:12 AM
Hi,
 
I am getting access token after login.
so that access token to get the values.
 
access token contains a model class that is :
 
public string AccessToken
{
get;
set;
}

public string TokenType
{
get;
set;
}
public double ExpiresIn
{
get;
set;
}
public string ExpireDateTimeUtc { get; set; } 
 
and my code is :
 
public partial class Form1 : Form
{


string URI;
string email = ConfigurationSettings.AppSettings["email"].ToString();
string password = ConfigurationSettings.AppSettings["password"].ToString();

public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void submit_Click(object sender, EventArgs e)
{
URI = string.Concat(host_textbox.Text, api_textbox.Text);

GetLogin();
}
#region Methods


private async void GetLogin()
{

using (var client = new HttpClient())
{

var login = new LoginData() { Email = email, Password =password };

var response = await client.PostAsJsonAsync(URI, login);

client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

if (response.IsSuccessStatusCode)
{

var productJsonString = await response.Content.ReadAsStringAsync();
LoginData loginObj= JsonConvert.DeserializeObject<LoginData>(productJsonString);
Body_textBox.Text = productJsonString;
}

else
{

var GetResponse = await client.GetAsync(URI);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
if(GetResponse.IsSuccessStatusCode)
{
var getjsonstring = await GetResponse.Content.ReadAsStringAsync();
TeamMemberData team = JsonConvert.DeserializeObject<TeamMemberData>(getjsonstring);
//JsonConvert.DeserializeObject<TeamMemberData>(getjsonstring);
Body_textBox.Text = getjsonstring;

}



}


}

}

private void Body_textBox_TextChanged(object sender, EventArgs e)
{

}
}
#endregion
 
How to get a values using access token. 
 Please give me code for that.
 
Thank you