angular6 - 有没有办法跳过Angular httpClient未处理的预检响应?
问题描述
我们正在使用 httpClient 和 withCredentials: true 开发一个 Angular 6 应用程序。当我们向同一服务器上的另一个端口(从端口 8010 到 8011)发出请求时,Firefox 会尝试发出预检请求。但似乎我们的角度 httpClient 正在尝试处理这个预检响应。我们正在使用下面的代码。我们看到,流程正在进入 catchError 块。为什么 angular-httpclient 处理预检响应?我们如何处理这个?
request(url: string, method: string, options?: any, xmlOptions?: any,
isFullUrl:boolean = false): Observable<any> {
const fullUrl = (isFullUrl) ? url : `${HttpService.BASE_URL}${url}`;
return this.httpClient.request(method, fullUrl, options).pipe(
map(resp => this.parseXML(resp, xmlOptions)),
catchError(exception => this.processError(exception, xmlOptions))
);
}
private processError(exception, xmlOptions) {
this.notificationService.clear();
this.notificationService.error(HttpService.UNEXPECTED_ERROR_OCCURRED);
if(exception.error) {
let errorObj = this.parseXML(exception.error, xmlOptions);
return throwError(errorObj);
}
else {
return throwError(exception);
}
}
如果我们检查异常,错误消息是"Http failure response for (unknown url): 0 Unknown Error"
注意:这在 Chrome 浏览器中运行良好。
解决方案
推荐阅读
- java - 将证书添加到 selenium 中的 chrome 选项
- algorithm - 在非加权图上找到最短路径的现有算法?
- apache-nifi - NiFi:如何从第一列获取最大时间戳?
- python - 这么多蟒蛇,我需要哪些?
- java - Passay生成密码不重复字符
- visual-studio-code - 如何将 Visual Studio Code 终端输出设置为英语
- apache - Docker apache图像,将日志存储在主机中?
- arrays - 数学运算二维数组中的单个元素 - Swift
- javascript - 布尔变量命名规则
- android - 无法在android studio中构建apk