Flurl 抛出异常 (MoveNext())
Flurl throws an exception (MoveNext())
我正在尝试通过 Flurl 从 WinForms 应用程序 (.Net Framework 4.7) 调用 Web API POST 操作 (.Net Core)。但是,当我尝试调试 Flurl 抛出的异常时,我的请求甚至没有进入控制器本身。
尝试逐行调试问题没有帮助。我想是因为Web API 和WinForms 是同一个解决方案中的两个不同项目,所以我无法进入从表单到控制器的调试?
at Flurl.Http.FlurlRequest.<HandleExceptionAsync>d__23.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.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Flurl.Http.FlurlRequest.<SendAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Flurl.Http.FlurlRequest.<SendAsync>d__19.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 Flurl.Http.HttpResponseMessageExtensions.<ReceiveJson>d__0`1.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.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at BTM.WinUI.APIService.<Insert>d__12`1.MoveNext() in C:\Users\User\Documents\Visual Studio 2019\Projects\APITest\APITest.WinUI\APIService.cs:line 61
基本上我实例化了我创建的 class 的对象并调用了我的 API 服务:
var entity = new UserRegistrationModel
{
Username = "test",
Email = "test@test.com",
Password = "test",
PasswordConfirmation = "test",
Roles = new List<int>()
};
entity.Roles.Add(1);
entity.Roles.Add(2);
await _service.Insert<User>(entity);
我的电话是这样的:
public async Task<T> Insert<T>(object request)
{
string url = "https://localhost:44365/api/users";
return await url.PostJsonAsync(request).ReceiveJson<T>();
}
我的控制器应该通过向数据库添加一个新用户并返回一个 User
对象来处理它,但是该方法的代码永远不会执行。
[HttpPost]
public User Post(UserRegistrationModel request)
{
return _service.Register(request);
}
可能是由于 HTTPS
,Flurl 无法向您的本地主机发送 POST 请求。尝试在您的 ASP NET Core Web API 项目中禁用 SSL。
我正在尝试通过 Flurl 从 WinForms 应用程序 (.Net Framework 4.7) 调用 Web API POST 操作 (.Net Core)。但是,当我尝试调试 Flurl 抛出的异常时,我的请求甚至没有进入控制器本身。
尝试逐行调试问题没有帮助。我想是因为Web API 和WinForms 是同一个解决方案中的两个不同项目,所以我无法进入从表单到控制器的调试?
at Flurl.Http.FlurlRequest.<HandleExceptionAsync>d__23.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.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Flurl.Http.FlurlRequest.<SendAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Flurl.Http.FlurlRequest.<SendAsync>d__19.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 Flurl.Http.HttpResponseMessageExtensions.<ReceiveJson>d__0`1.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.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at BTM.WinUI.APIService.<Insert>d__12`1.MoveNext() in C:\Users\User\Documents\Visual Studio 2019\Projects\APITest\APITest.WinUI\APIService.cs:line 61
基本上我实例化了我创建的 class 的对象并调用了我的 API 服务:
var entity = new UserRegistrationModel
{
Username = "test",
Email = "test@test.com",
Password = "test",
PasswordConfirmation = "test",
Roles = new List<int>()
};
entity.Roles.Add(1);
entity.Roles.Add(2);
await _service.Insert<User>(entity);
我的电话是这样的:
public async Task<T> Insert<T>(object request)
{
string url = "https://localhost:44365/api/users";
return await url.PostJsonAsync(request).ReceiveJson<T>();
}
我的控制器应该通过向数据库添加一个新用户并返回一个 User
对象来处理它,但是该方法的代码永远不会执行。
[HttpPost]
public User Post(UserRegistrationModel request)
{
return _service.Register(request);
}
可能是由于 HTTPS
,Flurl 无法向您的本地主机发送 POST 请求。尝试在您的 ASP NET Core Web API 项目中禁用 SSL。