[英]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:这是我提出请求的代码:
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') }) };
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 模块:
Open iis server, select server name.打开iis服务器,select服务器名称。
Double click on modules双击模块
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.