.net - http://localhost:xxxx/api/values 无法在 .net core 2.2 中加载页面
问题描述
我正在使用 .net core 2.2 使用 WebApi。如果我使用 URL https://localhost:44352/api/values访问 API ,它可以正常工作。但是,如果我改为使用http://localhost:44352/api/values,使用 HTTP 而不是 HTTPS,则无法加载。
这是 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();
}
谁能向我解释什么是错的?
解决方案
由于app.UseHttpsRedirection();
,您将管道设置为将每个 HTTP 调用重定向到 HTTPS。
所以首先,删除这条线。
然后,删除app.UseHsts();
. 如果您不想使用 HTTPS,则无需强制使用 SSL。
现在,您应该能够使用 HTTP 调用来调用您的 API。
推荐阅读
- flutter - I/flutter (29011): NoSuchMethodError: 在 null 上调用了方法“插入”。SQFLITE 颤动
- c++ - char 和 int 中 **(ptr+1) 值的差异
- java - Hibernate Envers 如何正确获取日志历史记录?
- spring-boot - 如何从密码 hashcorp vault 动态读取 liquibase.properties
- react-native - 不要在可重用组件之间共享状态反应原生
- arm - Neon - 使用 vld1q_s32 从数组中加载一个元素
- flutter - 如何在我的应用程序中添加 Flutter API/模块?
- android-studio - Android Studio 4.0 中的 BottomNavigationView 和 TabLayout 之间的 Tab UI 有何不同?
- android - 分组通知触发相同的待处理意图
- bash - 检测单色图像中最右边黑色像素的 x 值?