E
E
ellz2019-02-09 18:52:38
.NET
ellz, 2019-02-09 18:52:38

Why is the method not responding to a request through ngrok?

There is a web api project on .net core 2, according to the standard VS template:

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

        public IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            //пытался так избавится от этой проблемы:
            services.AddCors(options =>
            {
                options.AddPolicy("AllowSpecificOrigin",
                builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());//по идеи все разрешено                               
            });

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

[EnableCors("AllowSpecificOrigin")]
    [Route("api/")]
    [ApiController]
    public class ValuesController : ControllerBase
    {       
        [HttpPost]        
        [EnableCors("AllowSpecificOrigin")]
        [Route("getToursList")]
        public string Post([FromBody] GettingTourInfo value)
        {
            return JsonConvert.SerializeObject(value);
        }
    }

If I send a request to the local server, via postman, then everything is fine. But if I send from another PC (or even from my own), through ngrok, then a request appears in ngork, and the client receives -
ERR_EMPTY_RESPONSE
, and the breakpoint on the method doesn't fire.
The request looks like this:
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);
        }
   })
};

Tried, besides ngrok, localtunel - same thing.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Silin, 2019-02-09
@byme

Replace https://localhost:5001;http://localhost:5000 with https://0.0.0.0:5001;http://0.0.0.0:5000

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question