An error occurred while sending the request.===22/02/2021 09:14:31 ------------------------------Stack Trace-------------------------------------------- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at SingPost.NMP.Client.Internal.Areas.PPP.Controllers.TransactionController.d__1fd.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.b__36(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.b__3f() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.b__32(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.b__1c() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult)===22/02/2021 09:14:31
I am getting above error message while call the API from my controller. Controller code
[HttpGet]
public async Task<ActionResult> ToEnableDisableARandRABasedonRateScheme(long mailSchemeId)
{
bool updated = false;
var headerSaveUri = string.Format("{0}/{1}/{2}", ClientConstant.WEBAPI_URI_PPI_TRANSACTION, APIMETOD_TOENABLEDISABLEARANDRABASEDONRATESCHEME, mailSchemeId);
var client = GetHTTPClient(headerSaveUri);
HttpResponseMessage responseMessage = await client.GetAsync(headerSaveUri);
if (responseMessage.IsSuccessStatusCode)
{
var responseData = responseMessage.Content.ReadAsStringAsync().Result;
updated = JsonConvert.DeserializeObject<bool>(responseData);
}
return Json(updated, JsonRequestBehavior.AllowGet);
}
HTTP code
public HttpClient GetHTTPClient(string uri)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(uri);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(ClientConstant.HTTP_TYPE));
return client;
}
In global.asax in application start event i added the below code also
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;