简体   繁体   English

Angular / .net core web Api hosted on IIS - HTTP Error 499 "No reason phrase" when trying to make a get request with https

[英]Angular / .net core web Api hosted on IIS - HTTP Error 499 "No reason phrase" when trying to make a get request with https

I hosted my .net core 5.0 web api on a windows server with IIS and HTTPS.I made some test requests with postman and all of them worked PERFECTLY, Now i tried to make the requests within my angular application and the httpclient from angular. I hosted my .net core 5.0 web api on a windows server with IIS and HTTPS.I made some test requests with postman and all of them worked PERFECTLY, Now i tried to make the requests within my angular application and the httpclient from angular. but nothing works.但没有任何效果。

This is my code for making the request:这是我提出请求的代码:

  1. Define the header定义 header

    const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Authorization': 'Basic ' + btoa('xyz:xyz') }) }; const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Authorization': 'Basic ' + btoa('xyz:xyz') }) };

  2. Make the request:提出请求:

    this.http.get("https://148.xxx.xxx.xxx:10023/simmanager/" + number, httpOptions).subscribe(r=>{ console.log(r)}, err =>{ console.log(err)); this.http.get("https://148.xxx.xxx.xxx:10023/simmanager/" + number, httpOptions).subscribe(r=>{ console.log(r)}, err =>{ console.日志(错误));

The result in the browser console is: browser errors浏览器控制台中的结果是:浏览器错误

I have no idea?我不知道? Is it a CORS error?是 CORS 错误吗? Is it because of false hosting?是因为虚假托管吗? I am hosting the EXACT same API with only HTTP and .net core 3.1 and it works.我正在托管完全相同的 API,只有 HTTP 和 .net 核心 3.1,它可以工作。 Maybe i made a mistake with CORS in .net core 5?也许我在 .net 核心 5 中对 CORS 犯了一个错误? Thank you for helping me out!谢谢你帮助我!

This is my cors policy:这是我的 cors 政策:

Startup.cs Configure Method: Startup.cs 配置方法:

app.UseCors(x => x
            .AllowAnyMethod()
            .AllowAnyHeader()
            .SetIsOriginAllowed(origin => true) // allow any origin
            .AllowCredentials()); // allow credentials

Startups.cs ConfigureServices Method: Startups.cs 配置服务方法:

            services.AddCors();

You could try to remove webdev module from iis:您可以尝试从 iis 中删除 webdev 模块:

  1. Open iis server, select server name.打开iis服务器,select服务器名称。

  2. Double click on modules双击模块

  3. Select webdevmodule and choose remove from action pane: Select webdevmodule 并选择从操作窗格中删除:

在此处输入图像描述

Then add custom headers as below to the site web.config file:然后将如下自定义标题添加到站点 web.config 文件中:

<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*"/>
    <add name="Access-Control-Allow-Headers" value="Content-Type"/>
    <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS,PUT,DELETE"/>
  </customHeaders>
</httpProtocol>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure 代理,CORs 请求时出错 IIS 托管 Z8A5DA52ED126447AD359E70C0572 - Azure Proxy, CORs error when request IIS hosted api 当在 IIS 中发布 .net 核心 web 应用程序的示例项目时,出现 Z293C9EA246FF99875DC6F62A5601 内部服务器错误。 - When Publish sample project of .net core web app in IIS getting HTTP Error 500.19 Internal Server Error 尝试使用 System.Net.Http 向 API 发出请求,但出现错误 - Trying to make a request to an API with System.Net.Http but getting errors NET Core Web API中如何使用HTTP get方法传递参数? - how to pass a argument with HTTP get method in .net core web api? 发布Angular 5 + .NET Core Web API时为空白页 - Blank page when publishing Angular 5 + .NET Core Web API 将删除请求从 angular 5 项目发送到 .net web Z8A5DA52ED12654E173 - 404 not found error when sending a delete request from angular 5 project to .net web api 在Mac上的.net-core中发出HTTP请求 - Make HTTP Request in .net-core on Mac angular and .net core 2.2 Web.config file issue when deploy on IIS windows 10 - angular and .net core 2.2 Web.config file issue when deploy on IIS windows 10 保护Angular 2的.Net Core Web Api - Securing .Net Core Web Api for Angular 2 如何将 .net Core 3.0 Web Api 托管在 Z5DA5ACF461B65EFB7E7ZEC86?0 - How to Host .net Core 3.0 Web Api on IIS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM