该方法为什么不通过ngrok响应请求?

时间:2019-02-10 16:27:21

标签: c# asp.net-core-2.0 ngrok

根据标准VS模板,.net core 2上有一个Web api项目:

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        // tried to get rid of this problem:
        services.AddCors(options =>
        {
            options.AddPolicy("AllowSpecificOrigin",
            builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());// by idea everything is allowed                                 
        });

        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseHsts();
        }

        app.UseCors("AllowSpecificOrigin");

        app.UseHttpsRedirection();
        app.UseMvc();
    }
}

如果我通过邮递员向本地服务器发送请求,则一切正常。但是,如果我是通过ngrok从另一台PC(甚至是我自己的PC)发送的,则会出现ngork请求,并且客户端进入-ERR_EMPTY_RESPONSE,该方法上的停止点不起作用。 查询看起来像这样:

var onSubmitClick = function () {
      $.ajax({
        url: URL_POST,
        headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
        },
        type: 'POST',
        data: jsonData,
        AccessControlAllowOrigin : '*', 
        AccessControlAllowHeaders : 'Content-Type',
        crossDomain: true,
        async: true,
        success: function(arr) {
            renderTours(arr);
        }
   })
};

launchsettings.json:

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false, 
    "anonymousAuthentication": true, 
    "iisExpress": {
      "applicationUrl": "http://localhost:52822",
      "sslPort": 44314
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Booking": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

我尝试过,除了ngrok,localtunel-也是一样。

0 个答案:

没有答案