dude, I used the same request method to request two interfaces, but found that the request headers was different and one of the requests failed
this is the request method I encapsulated
get(url, params: Object = {}): Observable<HttpResponse> {
let httpParams = new HttpParams();
Object.keys(params).map(key => {
httpParams = httpParams.set(key, params[key]);
});
if (this.localStorage.getItem("wechat_access_token")) {
const httpHeaders = new HttpHeaders({
"Access-Token": this.localStorage.getItem("wechat_access_token"),
"Access-Control-Allow-Origin": "*",
});
return this.http.get<HttpResponse>(environment.host + url, {
params: httpParams,
headers: httpHeaders
});
} else {
return this.http.get<HttpResponse>(environment.host + url, {
params: httpParams,
});
}
}
the first interface initiates the request and request header
getProduct(productId: any, shopId: string): Observable<HttpResponse> {
return this.get("shop/index/product", {
id: productId,
shop_id: shopId
});
}
request header
it is found that the request header of the two requests is different, and the access-token of one of the requests is not added to cause the request to fail. Excuse me, bosses, what is the reason for this?