User-1204637165 posted
So I have a peice of code am using this code to make a post request to some other Endpoint in my controller. So I would explain so you all understand.
I have a platform were I have users. My users are merchants. My merchants supply a call back url or webhook when signing up on my platform, I am suppose to post information to the webhook of my merchant.
I also have partners. My partners call my app through an Endpoint. when they call my app via a Post request. I am suppose to make a post request to my merchants web hook.
Unfortunately the code that makes a post request to my merchant webhook blocks IO. I tried making it async but it still blocks IO. The block happens when there is a communication when the merchant webhook . This block is affectiing the communication between
my endpoint and my partners.
I want a scenario were If I make a post to my merchant endpoint. Either there is an authentication issue or a post error to my merchant webhook, this should have no effect on the flow of my application.
This happens when there is a probably and authenitication issue with the Merchant Webhook. Here is my code below
public async Task Posttowebservice(string Url,string AuthorizeType, string Token, string Jsonbody)
{
//string responseResponse = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
try
{
request.Method = "POST";
request.ContentType = "application/json";
request.Timeout = 1000000;
//request.ContinueTimeout=
if(Token != null)
request.Headers.Add("Authorization Bearer ",Token);
request.Accept = "application/json";
request.ContentLength = Jsonbody.Length;
using (Stream webStream =await request.GetRequestStreamAsync())
using (StreamWriter requestWriter = new StreamWriter(webStream, System.Text.Encoding.ASCII))
{
await requestWriter.WriteAsync(Jsonbody);
// await requestWriter.FlushAsync();
}
await request.GetResponseAsync();
//
}
catch (Exception e)
{
Console.Out.WriteLine("-----------------");
Console.Out.WriteLine(e.Message);
logger.LogError("Problem from the Merchant Webhook \n"+e.Message);
}
finally
{
request.Abort();
}
}
I am looking at posting in a way that the entire application flows without been blocked either there is an error in the POST request or not.