angular - Angular HttpClient 简单的 GET 发送预检选项。如何强制我的 GET 保持简单请求?
问题描述
正如标题所述,我想发出一个没有预检选项的简单 GET 请求,因为服务器没有响应“Access-Control-Allow-Origin”标头,我无法更改这些服务器设置。
我的代码相当简单:
export interface HttpOptions {
headers?: HttpHeaders;
params?: HttpParams;
observe?: 'body';
}
private getProfileDetails() {
const httpOptions: HttpOptions = {
headers: new HttpHeaders({
'Content-Type': 'text/plain'
}),
params: new HttpParams()
.set('service', 'http%3A%2F%2Flocalhost%3A4200')
.append('ticket', this.currentTicket)
};
this.http.get('https://server.address/val', httpOptions).subscribe(data => {
console.log(data);
});
}
由于某种原因,浏览器不断收到错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
据我了解,这应该是一个简单的 GET 请求,不需要 OPTIONS,所以我对如何继续感到茫然。
任何提示将不胜感激。
解决方案
您将需要探索为您的 API 请求设置 angular-cli 代理。
https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md
推荐阅读
- google-sheets - 使用 Google 表格函数在单个单元格中创建格式化的有序对
- c++ - 为什么 const char* 到 const char 转换时出错?
- c# - 无需用户输入密码的无头 UWP 蓝牙配对
- java - 由于某种原因无法调用方法
- node.js - Node.js 更改已运行子进程的 stdio(取消引用它)
- c++ - 使用指针交换整数
- arrays - Swift:编写将从数组中调用随机项而不再次调用该项的代码
- python - 如何使用 pymel(或 maya.cmds)将自定义 UVset 中的 UV 链接到 Maya 中的纹理
- python - 如何有效地组合许多 numpy 数组?
- typescript - Ionic 3如何接收从一页到另一页的数组