An error occurred while sending the request.===22/02/2021 09:24:45
------------------------------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 Areas.PPP.Controllers.TransactionController.<EditTransaction>d__7.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.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)===22/02/2021 09:24:45
I am getting above error message while call the API from my controller. Controller code
controller code
[HttpGet]
public async Task<ActionResult> EditTransaction()
{
Session[ClientConstant.THEME_CLAPPER_TOGGLE] = ClientConstant.THEME_CLAPPER;
TransactionSetUpViewModel ViewModel = new TransactionSetUpViewModel();
long transactionHeader = (long)TempData[CARRIER_ID_FOR_TEMP];
TempData.Keep(CARRIER_ID_FOR_TEMP);
var uri = string.Format("{0}/{1}/{2}/{3}", ClientConstant.WEBAPI_URI_TRANSACTION, API_TRANSACTIONGETEDITMODEL,
transactionHeader, (int)ActionModes.EDIT);
HttpClient client = GetHTTPClient(uri);
HttpResponseMessage responseMessage = await client.GetAsync(uri);
if (responseMessage.IsSuccessStatusCode)
{
var responseData = responseMessage.Content.ReadAsStringAsync().Result;
try
{
ViewModel = JsonConvert.DeserializeObject<TransactionSetUpViewModel>(responseData);
if (ViewModel.PreDefinedList == null)
{
ViewModel.PreDefinedList = new List<SelectListItem>();
}
ViewModel.ActionMode = (int)ActionModes.EDIT;
ViewModel.IsOnlineMode = ClientConstant.ISONLINE_MODE;
return View("TransactionAction", ViewModel);
}
catch (System.Exception ex)
{
throw ex;
}
}
return View(ClientConstant.VIEW_ERROR);
}
HTTP client
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;