How to Set withCredentials:true in Angular 6 HttpClient.
See original GitHub issueHI Guys,
Am facing a issue which is related to withCredentials:true in angular6 httpClient.In my project need to send the {withCredentials:True} in Headers.Am sending this like below code . could you please check and let me know. API is working but am not getting the setCookie key,value from the responseHeaders. Am running in the localhost. Here is the code.Let me know guys if u need more info about this.
Code
let headers;
if (reqUrl == ‘validateSoftLoginInvestor’ || ‘validateOTP’ || ‘loadSoftLoginDetails’) {
headers = new HttpHeaders({ ‘Content-Type’: ‘application/x-www-form-urlencoded’, ‘withCredentials’: ‘true’ });
} else {
headers = new HttpHeaders({ ‘Content-Type’: ‘application/json’, ‘Accept’: ‘application/json’, ‘Authorization’: localStorage.getItem(‘accessToken’) });
}
return this.http.post(${this.baseUrl}
+ reqUrl, body, headers).pipe(
map((res: HttpResponse<Object>) => res))
}
Current behavior
Am not getting the setCookie key with value from the response headers.From where i can send the {withCredentials:true} in httpClient.
Expected behavior
want to get the setCookie key value from the response Headers.
Environment
Angular version:6.1.0
**Thanks in Advance Guys.**
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top GitHub Comments
@GopiKrishna10 … can you read the docs on https://angular.io/guide/http first?
@joesleiman I would recommend, that you check first, if the
withCredentials
property is already set. I just lost some time in debugging, why my http request wasn’t considering mywithCredentials: false
config:EDIT: I just realized, that the default of
withCredentials
isfalse
. So unfortunately this is not the correct way to skip this interceptor. But I found a solution that is using the header to indicate, that the interceptor should be skipped: https://stackoverflow.com/a/49047764/5816097.It needs a little bit more code, but I don’t know another way to solve this issue.