我有一个在http://172.17.0.2:4200运行的Angular应用程序和一个在http://172.17.0.2/lumen-app/public/api/v1运行的Lumen API
如果我用标题进行任何post / get调用,则会引发Cross Origin错误。 Angular强制发送OPTIONS作为方法。
我的角度代码
Highcharts.chart('container', {
"tooltip" : {
"shared" : true
},
"legend" : {
"enabled" : true,
"reversed" : false
},
"credits" : {
"enabled" : false
},
"exporting" : {
"enabled" : false
},
"chart" : {
"zoomType" : "xy"
},
"title" : {
"text" : "Financial analytic"
},
"xAxis" : [ {
"categories" : [ "Amar", "Kiran", "Venkatesh" ],
"crosshair" : true
} ],
"yAxis" : [ {
"title" : {
"text" : "Financial"
},
"labels" : {
"format" : "${value:.2f}USD"
}
} ],
"series" : [ {
"type" : "column",
"name" : "Financial",
"data" : [ 1325000.0, 1740000.0, 1560000.0 ],
"tooltip" : {
"valueDecimals" : 2,
"valuePrefix" : "$",
"valueSuffix" : "USD"
},
"yAxis" : 0
}]
});
.httaccess我已添加“允许来源”,如下所示:
$(document).ready(function() {
//llave publica del comercio
//Referencia de payco que viene por url
var ref_payco = getQueryParam('ref_payco');
//Url Rest Metodo get, se pasa la llave y la ref_payco como paremetro
var urlapp = "https://secure.epayco.co/validation/v1/reference/" + ref_payco;
$.get(urlapp, function(response) {
if (response.success) {
$.post( "your/endpoint", response.data );
}
});
/////
///
//
注意:有趣的是,如果我在不使用标头参数的情况下调用该服务,则它正在运行。 例子
return this.http.get(this.App.API_URL+'users',{
headers: new HttpHeaders({
"Content-Type": 'application/json'
})}).subscribe(response=>{
console.log(response)
});