我正在使用Angular 5进行一个内部项目。 在这里,我们试图对PCF环境中存在的一个URL进行Http GET调用。 拨打电话时,我收到控制台消息下方:
选项https://riskassessmentidtypes.px-npe01.com/customer-credit/ 0()
ProgressEvent {isTrusted:true,lengthComputable:false,loading:0,total:0,type:“ error”,...}
我的代码: processrequest.component.ts
this.httpService.getDetails(url, data).subscribe(
res => {
this.loading = false;
console.log("response-----" + res);
this.serviceresponsetime = new Date().getTime() - startFrom;
},
error => {
this.loading = false;
console.log(error);
this.serviceresponsetime = new Date().getTime() - startFrom;
//util.parseServiceResponse(error, false);
//this.responseData = util.responseData;
}
);
http.service.ts
@Injectable()
export class HttpService {
data: any;
headers = new Headers();
constructor(private http: Http) {
this.headers.append('Content-Type', "application/json");
this.headers.append('Accept', "application/json");
this.headers.append('senderid', "dsd");
this.headers.append('applicationid', "adsd");
this.headers.append('servicetransactionid', "asds");
this.headers.append('channelid', "asdsd");
}
// get service call
getDetails(url, params) {
console.log("http service - inside getDetails function");
let options = new RequestOptions();
options.headers = this.headers;
if (params) {
options.params = params;
}
return this.http.get(url, options)
.map((response) => response.json())
.catch((error: any) => Observable.throw(error.json() || 'server error'));
}
非常感谢。由于我是Angular的新手,所以我被困在这里。请在错误下方找到:
OPTIONS https://riskassessmentidtypes.px-npe01.com/customer-credit/ 0 ()
scheduleTask @ polyfills.bundle.js:5050
webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ polyfills.bundle.js:2488
onScheduleTask @ polyfills.bundle.js:2378
webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ polyfills.bundle.js:2482
webpackJsonp.../../../../zone.js/dist/zone.js.Zone.scheduleTask @ polyfills.bundle.js:2313
webpackJsonp.../../../../zone.js/dist/zone.js.Zone.scheduleMacroTask @ polyfills.bundle.js:2336
scheduleMacroTaskWithCurrentZone @ polyfills.bundle.js:3195
(anonymous) @ polyfills.bundle.js:5082
proto.(anonymous function) @ polyfills.bundle.js:3475
(anonymous) @ vendor.bundle.js:108570
webpackJsonp.../../../../rxjs/_esm5/Observable.js.Observable._trySubscribe @ vendor.bundle.js:2604
webpackJsonp.../../../../rxjs/_esm5/Observable.js.Observable.subscribe @ vendor.bundle.js:2592
webpackJsonp.../../../../rxjs/_esm5/operators/map.js.MapOperator.call @ vendor.bundle.js:20860
webpackJsonp.../../../../rxjs/_esm5/Observable.js.Observable.subscribe @ vendor.bundle.js:2589
webpackJsonp.../../../../rxjs/_esm5/operators/catchError.js.CatchOperator.call @ vendor.bundle.js:17393
webpackJsonp.../../../../rxjs/_esm5/Observable.js.Observable.subscribe @ vendor.bundle.js:2589
webpackJsonp.../../../../../src/app/processrequest/processrequest.component.ts.ProcessrequestComponent.onSubmit @ main.bundle.js:749
(anonymous) @ ProcessrequestComponent.html:59
handleEvent @ vendor.bundle.js:92877
callWithDebugContext @ vendor.bundle.js:94386
debugHandleEvent @ vendor.bundle.js:93973
dispatchEvent @ vendor.bundle.js:89292
(anonymous) @ vendor.bundle.js:89917
(anonymous) @ vendor.bundle.js:113109
webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask @ polyfills.bundle.js:2502
onInvokeTask @ vendor.bundle.js:84039
webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask @ polyfills.bundle.js:2501
webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask @ polyfills.bundle.js:2269
webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask @ polyfills.bundle.js:2577
invokeTask @ polyfills.bundle.js:3621
globalZoneAwareCallback @ polyfills.bundle.js:3647
main.bundle.js:755 ProgressEvent {isTrusted: true, lengthComputable: false, loaded: 0, total: 0, type: "error", …}
答案 0 :(得分:0)
据我所知,许多浏览器的确在发送其他任何请求之前先发送了一个选项请求。您可以在浏览器开发工具中经常观察到这种行为。据我所知这不是一个角度问题,而是浏览器问题。
答案 1 :(得分:0)
我通过在目标springboot微服务的端点方法级别使用@CrossOrigin来解决了这个问题。
我们也可以在控制器类中使用它。