0

I am using react js for front end and spring boot for backend process. I need to send cookies from front end to backend for which I am trying following approach using axios:

Frontend

async function submitPageData() {
    try {
      const jwttoken = {
        headers: {
          jwt: to12,
          Cookie: token
        }
      };
      const response = await axios
        .put(
          url,
          {
            id: pageId,
            projectName: PROJECT_NAME,
            title: title
          },
          jwttoken
        )
        .then(function () {

       });
    } catch (error) {
        }
      }
    }
  }

And receiving cookies at backend using @CookieValue annotation but as I checked and found that my request header is not carrying Cookie with it.

Please guide me, how can I send cookie from react js axios method so that I will able to receive it at backend.

Edit

const jwttoken = {
        headers: {
          jwt: to12,
          Cookie: token,
          withCredentials: true
        }

Thanks in advance!

dur
  • 15,689
  • 25
  • 79
  • 125
Balram Chauhan
  • 171
  • 1
  • 2
  • 14
  • Check out the answer in here : https://stackoverflow.com/questions/43002444/make-axios-send-cookies-in-its-requests-automatically – Morta1 Dec 27 '19 at 11:17
  • I have tried this thing as well inside my header as edit is updated in the question itself but still no sign of cookie in request header. – Balram Chauhan Dec 27 '19 at 11:28
  • @BalramChauhan did you find any solution for this issue. – Vishali Jun 16 '22 at 15:53

1 Answers1

0

For some reason, using withCredentials as a header doesn't work for me either.

This to add it like that:

import axios from "axios";
axios.defaults.withCredentials = true;
Morta1
  • 609
  • 7
  • 20
  • Thanks for reply. I tried this approach as well but using this my axios is sending options request only and getting 200 in response but after options request it is enable to send put request. – Balram Chauhan Dec 27 '19 at 12:21
  • Also, it has stopped the normal flow of the application. Now, evevy page is taking multiple hits to load it successfully. – Balram Chauhan Dec 27 '19 at 12:37