我在 IIS 上有一个简单的 webApi 应用程序。有一个MessageController是 ControllerBase 和[Route("api/[controller]"), ApiController]. 那里我有[HttpPost] public IActionResult Send([FromBody] MessageViewModel message)两个字段模型的唯一方法。然后,我有一个向 webApi 发送消息的 ApiConnector:public class ApiConnector : IDisposable{ private readonly HttpClient _client = new HttpClient(); private readonly string _apiUrl; public ApiConnector(string apiUrl) => _apiUrl = apiUrl; public void SendMessage(string sender, string message) { try { _client.PostAsJsonAsync($"{_apiUrl}/message", new { sender, message }); } catch { } }}一切都是用 Asp Core 2.2 编写的。当我从 ConsoleApp(while(true)循环内部)运行 ApiConnector 时,一切正常。当我从邮递员发帖时,一切正常。但是,一旦我尝试从任何其他地方(应用程序,我想没有无限循环)做同样的事情,WebApi 的控制器就会崩溃。消息:客户端已断开连接;内部消息:尝试读取流的末尾。如何正确发送此请求?无论如何都有异常文本:"Message":"The client has disconnected","Data":{},"InnerException":{ "ClassName":"System.IO.EndOfStreamException", "Message":"Attempted to read past the end of the stream.", "Data":null, "InnerException":null, "HelpURL":null, "StackTraceString":null, "RemoteStackTraceString":null, "RemoteStackIndex":0, "ExceptionMethod":null, "HResult":-2147024858, "Source":null, "WatsonBuckets":null},"StackTrace":" PS我试过Wait()_client的结果无济于事。
- 1 回答
- 0 关注
- 183 浏览
添加回答
举报
0/150
提交
取消