.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);
}

浙公网安备 33010602011771号