1

I am working with WebApi using .net core 2.2. If I access the API with URL https://localhost:44352/api/values, it works fine. But if I changed to use http://localhost:44352/api/values, using HTTP instead of HTTPS, it could not load.

This is Configure in Startup.cs

 public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } //app.UseSwagger(); //app.UseSwaggerUI(x => //{ // x.SwaggerEndpoint(@"/swagger/v1/swagger.json", "My Api v1"); // x.RoutePrefix = "api"; //}); app.UseHttpsRedirection(); app.UseMvc(); } 

Can anyone explain to me what is wrong?

1 Answer 1

2

Because of app.UseHttpsRedirection();, you are setting your pipeline to redirect each HTTP call to HTTPS.

So first of all, remove this line.

Then, remove app.UseHsts();. You do not need to force SSL if you don't want to use HTTPS.

Now, you should be able to call your API using HTTP calls.

Sign up to request clarification or add additional context in comments.

1 Comment

@ Skrface. Thank you. It worked. It seems I misunderstood the debug project setting. The port for HTTP and HTTPS are different but I used the same port while testing.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.