I have given below the sample code, I am calling web API but I am struggling to pass the parameter in the console application.
C# code:
HttpClient client = new HttpClient(); var responseTask = client.GetAsync("<web api name>"); responseTask.Wait(); HttpRequestMessage rm = new HttpRequestMessage(); var headers = rm.Headers; client.DefaultRequestHeaders.Add("client_id", "1234xv"); client.DefaultRequestHeaders.Add("client_secret", "7dfdfsd"); if (responseTask.IsCompleted) { var result = responseTask.Result; if (result.IsSuccessStatusCode) { var messageTask = result.Content.ReadAsStringAsync(); messageTask.Wait(); Console.WriteLine("Message from Web API:" + messageTask.Result); Console.ReadLine(); } }
awaitfor the async calls instead of.ResultorWait()