Request for Advice on using HttpClient in a Controller

  • Thread starter Thread starter DoctorWhoKnew
  • Start date Start date
D

DoctorWhoKnew

Guest
private const string AmerOAuthUrl = "https://api.tdameritrade.com/v1/oauth2/token";

[HttpGet("{symbol}")]
public async Task<Cagr> GetQuoteAsync(string symbol)
{

using (var message = new HttpRequestMessage(HttpMethod.Post, AmerOAuthUrl))
{
//Build the parameters same as before
var parameters = new Dictionary<string, string> { { "application/x-www-form-urlencoded", "grant_type=refresh_token&refresh_token=kf67WLD/ZAD3XUD7iDId7+cGHdGEIu1VVT4ZgF5eN5Npm/yVuRpSJ0FdIiL57SMrR &client_id=AMN@AMER.OAUTHAP&redirect_uri=http://localhost" } };
var encodedContent = new FormUrlEncodedContent(parameters);

//Set the content of the request message object to your paramaters
message.Content = encodedContent;

//Send the request and await the response.
var response = await httpclient.SendAsync(message);


if (response.StatusCode == HttpStatusCode.OK)
{
// Do something with response. Example get content:
// var responseContent = await response.Content.ReadAsStringAsync ().ConfigureAwait (false);
}
}

I get an error running this code, 'response not defined

Continue reading...
 
Back
Top