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 Results From Across the Web
Angular 6 set withCredentials to true with every HttpClient call
Create a HttpInterceptor : @Injectable() export class CustomInterceptor implements HttpInterceptor { intercept(request: HttpRequest<any>, ...
Read more >
Creating a custom HttpInterceptor to handle 'withCredentials ...
For this post, I needed to create and hook up a custom HttpInterceptor in Angular 6. There's lots of information from previous versions...
Read more >
HttpClient - Angular
Constructs an observable for a generic HTTP request that, when subscribed, fires the request through the chain of registered interceptors and on to...
Read more >
Communicating with backend services using HTTP - Angular
Observable techniques and operators. See the Observables guide. Setup for server communicationlink. Before you can use HttpClient , you need to import the ......
Read more >
Angular Basics: How To Use HttpClient in Angular - Telerik
Let's see how to use this HttpClient module in an Angular application. This module is already included in the application when we create...
Read more >
Top Related Medium Post

No results found
Top Related StackOverflow Question

No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
21reactions
mlc-mlapiscommented, Sep 19, 2018
@GopiKrishna10 … can you read the docs on https://angular.io/guide/http first?
1reaction
hpawe01commented, Jul 15, 2019
@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.
Read more comments on GitHub >