0

How can I send the parameters with GET request?

using (HttpClient client = new HttpClient())
{

    List<KeyValuePair<string, string>> queryParameters = new List<KeyValuePair<string, string>>
    {
        new KeyValuePair<string, string>("client_id", clientId),
        new KeyValuePair<string, string>("response_type", "code"),
        new KeyValuePair<string, string>("redirect_uri", redirectUri),
        new KeyValuePair<string, string>("state", "qwe123"),
    };

    HttpContent content = new FormUrlEncodedContent(queryParameters);

    client.

    HttpResponseMessage resp = await client.GetAsync("https://uri", content); //here is mistake

    string responseBody = await resp.Content.ReadAsStringAsync();

    Console.WriteLine(responseBody);
}

I tried to use KeyValuePair for configuring parameters. Thanks!

Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
Lost_
  • 9
  • 1
  • 4

1 Answers1

0

GetAsync doesn't take HttpContent as a second param in any of its overloaded methods, please check supported overloaded methods ms doc here

Have a look at similar case here

But, if you can change the api portion then better to change this to POST instead of GET

var response = await httpClient.PostAsync("https://uri", new FormUrlEncodedContent(queryParameters));
var contents = await response.Content.ReadAsStringAsync();
mabiyan
  • 667
  • 7
  • 25