Angular 8 - httpClient Get 方法转换为 Options 方法 [英] Angular 8 - httpClient Get method transforms to Options method
本文介绍了Angular 8 - httpClient Get 方法转换为 Options 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试向我的服务器(Microsoft 2012)发送 Get 请求.我已经添加了这个解决方案.但在这个解决方案中,我的 get 请求转换为 Options 方法.
I am trying to send Get request to my server(Microsoft 2012). I have already added this solution. But in this is solution my get request transformed to Options method.
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/vnd.sas.datamgmt.jobflow.metadata+json; charset=utf-8',
'Authorization': 'Basic' + btoa('username:password')
})
};
我还补充了:
httpOptions.headers.set('username', 'password');
httpOptions.headers.append('Access-Control-Allow-Origin', '*');
httpOptions.headers.append('Access-Control-Allow-Credentials', 'true');
httpOptions.headers.append('Access-Control-Allow-Methods', 'GET,POST,OPTIONS');
this.typesOfDBs = this.http.get<Info[]>(this.ROOT_URL, httpOptions);
我看了我的请求,我看到请求现在是选项请求.我如何处理它并将请求作为 Get 方法发送?
I watched my request and I saw the request is now Options request. How can I handle it and send request as Get method?
推荐答案
我用 nodejs 代理解决了这个问题.Nodejs 很容易处理它.您必须从 angular 向 nodejs 发送请求.并从 nodejs 恢复.
I used nodejs proxy to solve this question. Nodejs handled it easily. You must send request to nodejs from angular. And to restapi from nodejs.
这篇关于Angular 8 - httpClient Get 方法转换为 Options 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文