我在 IIS 上有一個簡單的 webApi 應(yīng)用程序。有一個MessageController是 ControllerBase 和[Route("api/[controller]"), ApiController]. 那里我有[HttpPost] public IActionResult Send([FromBody] MessageViewModel message)兩個字段模型的唯一方法。然后,我有一個向 webApi 發(fā)送消息的 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 編寫的。當(dāng)我從 ConsoleApp(while(true)循環(huán)內(nèi)部)運(yùn)行 ApiConnector 時,一切正常。當(dāng)我從郵遞員發(fā)帖時,一切正常。但是,一旦我嘗試從任何其他地方(應(yīng)用程序,我想沒有無限循環(huán))做同樣的事情,WebApi 的控制器就會崩潰。消息:客戶端已斷開連接;內(nèi)部消息:嘗試讀取流的末尾。如何正確發(fā)送此請求?無論如何都有異常文本:"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的結(jié)果無濟(jì)于事。
- 1 回答
- 0 關(guān)注
- 197 瀏覽
添加回答
舉報
0/150
提交
取消