0

How to generate csrf token in ionic.? i m using django framework as server and wish to post data to server.

This are my error:

Forbidden (403) CSRF verification failed. Request aborted. You are seeing this message because this site requires a CSRF cookie when submitting forms. This cookie is required for security reasons, to ensure that your browser is not being hijacked by third parties. If you have configured your browser to disable cookies, please re-enable them, at least for this site, or for 'same-origin' requests. Help Reason given for failure: CSRF cookie not set.

Here are my code:

postRequest() {
 var headers = new Headers();
 headers.append("Accept", 'application/json');
 headers.append('Content-Type', 'application/json');

let options = new RequestOptions({ headers: headers });
let body1 = {
  site: this.selectedSite,
   zone: this.selectedZone,
   user: this.username,
   categoryType: this.problemType,
   conNo:'012-8888888'}


this.http.post("http://localhost:8000/apidb/simple_upload", JSON.stringify(body1), options)
  .subscribe(data => {
    resolve(data);
  }, error => {
    console.log(error);
  });}
Heng
  • 13
  • 1
  • 5
  • How are you implementing the authentication on your backend? It shouldn't request CSRF tokens for non cookie/session based authentication. – hugobessa Dec 14 '17 at 03:56
  • How are you fixing this issue? I got the same problem – Maxx Mar 24 '18 at 19:13

1 Answers1

0

It doesn't look like your content type in the request is being set. You need to set it to 'applicatioon/json' and then it won't require CSRF

kevswanberg
  • 2,079
  • 16
  • 21