On Http Post request HttpClient X-XSRF-Token are not setting in an Angular 6
See original GitHub issueimport {HttpClientModule, HttpClientXsrfModule} from "@angular/common/http";
imports: [
...
HttpClientModule,
HttpClientXsrfModule.withOptions({
cookieName: 'XSRF-TOKEN',
headerName: 'X-CSRF-TOKEN'
})
],
...
import {HttpClient, HttpClientModule, HttpClientXsrfModule} from "@angular/common/http";
constructor(private _http:HttpClient) { }
addUser(info){
return this._http.post(this.apiURL, info, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
withCredentials: true,
responseType: "arraybuffer",
}
}
The default interceptor created behind the scene by HttpClientXsrfModule does not seem to handle absolute urls…
So I’ve changed the apiURL = “http://localhost/simple_api/insert.php”; TO apiURL = “//localhost/simple_api/insert.php”;
Working Fine. But unable var_dump or print the headers attached in the PHP script. But I’m getting the form data submitted successfully.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Angular 6 does not add X-XSRF-TOKEN header to http request
The problem once again is Angular's poor documentation. The fact is, Angular will add the X-XSRF-TOKEN header only if the XSRF-TOKEN cookie ...
Read more >HttpClientXsrfModule - Angular
Configures XSRF protection support for outgoing requests. ... the default cookie name is XSRF-TOKEN and the default header name is X-XSRF-TOKEN .
Read more >Angular CSRF Protection Guide: Examples and How to Enable It
Since our application server is sending us a token named XSRF-TOKEN, we'll use Angular's HttpClientXsrfModule to protect every outgoing request ...
Read more >Fix "Invalid CSRF token" error – add the XSRF-TOKEN header ...
Angular provides a built-in support for sending requests secured with the XSRF-TOKEN header. However, it won't add the token to absolute ...
Read more >Angular 6 does not add X-XSRF-TOKEN header to http request
this.http .post<any>('api/login', {'_username': username, '_pass': password}) .subscribe(/* handler here */);. The post request ...
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 FreeTop 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
Top GitHub Comments
@benlesh @manekinekko
Click Here
Here is my complete code. As I’m new to run this code
From the usr.service.ts it was consoling all the headers after posting the data Headers should be posted or printed with XSRF Token on the console. But it’s not going to happen?
I have a screen Shot of console Click
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.