用StreamReader异步读取httpcontext时,部署时偶尔会报错
using (StreamReader streamReader = new StreamReader(HttpContext.Request.Body))
{
string model = await streamReader.ReadToEndAsync();
}
改成同步读取后,部署后未发现异常
using (StreamReader streamReader = new StreamReader(HttpContext.Request.Body))
{
string model = streamReader.ReadToEnd();
}
其中配置时要允许同步读取
public void ConfigureServices(IServiceCollection services)
{
services.Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);
}