我正在尝试从我的anguar 4应用发出POST呼叫。该请求在浏览器上被取消。但是,当我在邮递员中复制相同的请求时,效果很好。
请求-/登出(POST),请求中包含空内容-{}
响应:
{
code: 200,
message: 'Logout successfully'
}
下面是iam如何解决发布请求
this.signinService.signOut().subscribe((data) => {
if (data && data.response == 1) {
localStorage.clear();
this.cookieService.remove(AppSettings.cookieName, { path: '/', secure: AppSettings.secure });
this.cookieService.remove(AppSettings.refreshCookieName, { path: '/', secure: AppSettings.secure });
}
});
我还试图检查是否存在CORS问题,并且在这方面没有问题。
服务中的退出方法
public signOut(): Observable<any> {
return this.HttpService.post('v2/logout', {});
}
HttpService
public post<T>(url: string, params: Object, options?: IRequestOptions): Observable<T> {
if (options && options.apiServer)
url = `${AppSettings[options.apiServer]}/${url}`;
else
url = `${AppSettings.API_ENDPOINT}/${url}`;
return this.http.post<T>(url, params, options).take(1).catch((err: HttpErrorResponse) => {
return Observable.throw(err);
});
}