zoukankan      html  css  js  c++  java
  • .net core api迁移 3.0后Post 405 Method Not Allowed

    问题由来:.net core api之前是用 .net core 2.0开发的,测试过都是正常的,近期升级到了3.0,发现api get正常,post提示400,405 Method Not Allowed

    查找没有找到原因,就在本地调试,提示错误信息:

    System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.

    错误原因:.net core 3.0不允许同步操作,必须改成异步方式

    解决方法:将原来的ReadToEnd(),修改为ReadToEndAsync(), 问题得到解决。

                using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
                {
                    result = await reader.ReadToEndAsync(); //升级3.0不允许同步操作,必须异步
                    Logger.Info("FactoryBarCode:" + result);
                }

     另一种办法:

    It's worth noting that if you host on kestrel directly then your Program.cs should have appropriate ConfigureKestrel call
    
       public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
                WebHost.CreateDefaultBuilder(args)
                    .UseStartup<Startup>()
                    .ConfigureKestrel((context, options) =>
                    {
                        options.AllowSynchronousIO = true;
                    })
  • 相关阅读:
    6554545555
    484844
    学习资料整理
    word加上尾注之后参考文献下面的横线去除
    数据结构+算法
    python编程
    计算机网络(1)
    数据结构
    数据分析笔试(3)
    数据分析笔试(2)
  • 原文地址:https://www.cnblogs.com/jopny/p/11823010.html
Copyright © 2011-2022 走看看