允许从 Arduino 向 .NET API 发出 HTTP POST 请求

Allow HTTP POST request to .NET API from an Arduino

我有一个应用程序在 Azure 上 运行,我正在尝试 post 从 ESP8266 到 https://myApplication.azurewebservices.net/api/call 的数据。但我什么也得不到。 ESP8266 似乎无法处理 HTTPS,所以我想我会尝试启用 HTTP POST 请求。

我的启动 class 看起来像这样:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("MyDatabase")));
            services.AddIdentity<User, IdentityRole>()
                .AddEntityFrameworkStores<AppDbContext>();
            services.AddCors();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseCors(options => options.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());
            app.UseDeveloperExceptionPage();
            app.UseAuthentication();
            app.UseMvcWithDefaultRoute();
        }

我认为通过允许 anyheaders、anyorigin 和 anymethod 将允许我 post HTTP 请求。

但是在 Postman 中尝试它仍然 returns 如果我这样做 http://myApplication.azurewebservices.net/api/call 则找不到 404,但是如果我使用 https://.

它确实有效

如何让我的应用程序接受完全相同但使用 HTTP 而不是 HTTPS 的请求?

您需要在 Azure 门户中为您的应用服务专门启用 HTTP 请求。

Dashboard > App Service > Custom Domains > disable "HTTPS only"