【发布时间】:2021-05-24 09:08:30
【问题描述】:
发送请求时出错。===22/02/2021 09:14:31 - - - - - - - - - - - - - - - 堆栈跟踪 - - - - - - - - - - - - - - - - - - - - - - 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() 在 SingPost.NMP.Client.Internal.Areas.PPP.Controllers.TransactionController.d__1fd.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.c__DisplayClass37.b__36(IAsyncResult asyncResult) 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d() 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.c__DisplayClass46.b__3f() 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.c__DisplayClass33.b__32(IAsyncResult asyncResult) 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.c__DisplayClass21.c__DisplayClass2b.b__1c() 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.c__DisplayClass21.b__1e(IAsyncResult asyncResult)===22/02/2021 09:14:31
我在从控制器调用 API 时收到上述错误消息。 控制器代码
[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 代码
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;
}
在应用程序启动事件的 global.asax 中,我还添加了以下代码
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
【问题讨论】:
-
如果您可以分享异常消息会很有帮助。
标签: c# asp.net-mvc api model-view-controller tcp