我正在通过以下方式在mvc .net核心项目中调用Web API,
client = new HttpClient();
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Employee Returnmodel = client.GetAsync("api/employee/find/" + Convert.ToInt32(id) + "").Result.Content.ReadAsAsync<Employee>().Result; //throws exception
以上代码引发以下异常
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred.
Source=System.Private.CoreLib
StackTrace:
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at EmployeeManagent.Web.Controllers.EmployeeController.EmployeeController.EmployeeData(User model, Nullable`1 id) in F:\C Partition\Documents\Tejas Training\EmployeeManagementSystem\EmployeeManagent.Web\EmployeeManagent.Web\Controllers\EmployeeController\EmployeeController.cs:line 61
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
Inner Exception 1:
HttpRequestException: No connection could be made because the target machine actively refused it
Inner Exception 2:
SocketException: No connection could be made because the target machine actively refused it