2

running django locally and with firefox, i login with http://localhost:8000/admin/ and after that i can access http://localhost:8000/myCustomApi successfully.

on insomnia every time i login with http://localhost:8000/admin/ i get {"code": "csrf", "reason": "CSRF cookie not set."} on the response. i tried this but didn't work. is there any tutorial to what should i do?

rado
  • 5,720
  • 5
  • 29
  • 51

2 Answers2

0
  1. Install this plugin: https://insomnia.rest/plugins/insomnia-plugin-default-headers
  2. Click on your environment and then on "Manage Environments" enter image description here

3. In your environment, add a new env var:

{
"DEFAULT_HEADERS": {
    "X-CSRFToken": "wSYUpsSIkXxjA8wBiojsCU7YgJGYySGFWiDHNoGhEpCWGxoIyNfIvw7hr2Au1a9J"
}

}

Replace the value with one you can find in your browser.

  1. Now, that was for sending data to forms. If you need to make a request while being loggued, click on Cookies and add a new cookie with a name sessionid and the value that you will find in your browser.

  2. Enjoy

Atem18
  • 107
  • 1
  • 6
0

Setting the X-CSRFToken didn't worked for me.

So I tried to "copy" the same request in the Insomnia environment.

In my case, what I did was:

  1. Go to your Browser and do at least one successful request.
  2. Go to Network tab and copy the Request Header with name Cookie.
  3. Go to Insomnia and set this same header with it values.
  4. Try debbugging from Insomnia.

enter image description here

Insomnia:

enter image description here

But if something seems different to you, just keep the same core: copy the request environment from browser to insomnia.

Remember the server can't see difference between an Insomnia client and the Browser if all the headers are the same.

Alex Rintt
  • 1,618
  • 1
  • 11
  • 18