.net core 3.0以上 Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead

private readonly IHttpContextAccessor _httpContextAccessor;//依赖注入
Stream reqStream = _httpContextAccessor.HttpContext.Request.Body; using (StreamReader reader = new StreamReader(reqStream)) { text = reader.ReadToEnd(); }

 

接口接收post数据时报错,因为AllowSynchronousIO默认为false,解决如下

 public override void ConfigureServices(ServiceConfigurationContext context)
{
      Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(x => x.AllowSynchronousIO = true);
      Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);
}

 

posted @ 2021-08-31 16:15  北极星下落不明  阅读(139)  评论(0)    收藏  举报