我正在尝试通过Flurl从WinForms应用程序(.Net Framework4.7)调用Web API POST操作(.Net核心)。然而,当我尝试调试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基本上,我实例化一个我创建的类的对象并调用我的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);
}发布于 2019-05-17 06:58:02
可能是由于HTTPS的原因,Flurl无法向您的本地主机发送POST请求。尝试在ASP NET Core Web API项目中禁用SSL。
https://stackoverflow.com/questions/56151705
复制相似问题