This below code is working fine, i just wanted to do it using webclient without async.
Or can we remove anyways asnc from below method and make it like regular method.
// Calling method from program.cs using console application
static void Main(string[] args)
{
AsyncCallbackUrlPost("f0c9b87f41fd0b7824ffdadeccefefefdd3c39929dbceca61b3450d497981a5eeeec354713d61263a71e3a953beebf62b12d6d9819ebb0593e7947766e8bef03", "http://localhost:54262/api/Payload");
Console.ReadLine();
}
// This method i want to replace with webclient
public static async Task AsyncCallbackUrlPost(string loanBeamMessageHash, string callbackURL)
{
HttpResponseMessage httpResponseMessage = null;
try
{
Uri objUri = new Uri(callbackURL);
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("LoanBeam_MessageHash", loanBeamMessageHash);
httpClient.DefaultRequestHeaders.Host = objUri.Host;
StringContent theContent = new StringContent(loanBeamMessageHash, System.Text.Encoding.UTF8, "application/json");
httpResponseMessage = await httpClient.PostAsync(objUri, theContent);
if (httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK)
{
Console.WriteLine("HTTP status success: " + httpResponseMessage.ReasonPhrase);
return;
}
else
{
return;
}
}
catch (Exception ex)
{
Console.WriteLine("HTTP status error: " + httpResponseMessage.ReasonPhrase);
}
}
What I have tried:
My above code is working fine, i just wanted to do it using webclient without async.