Home >Backend Development >Golang >Why Is My Browser Rejecting Set-Cookie Headers from Cross-Origin Responses?

Why Is My Browser Rejecting Set-Cookie Headers from Cross-Origin Responses?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-18 06:30:02611browse

Why Is My Browser Rejecting Set-Cookie Headers from Cross-Origin Responses?

Browser Rejects Set-Cookie Header from Cross-Origin Response

You encounter an issue where your front end fails to set an HTTP cookie received from the back end. The issue stems from an improper configuration of 'withCredentials' in the client code.

To resolve this, ensure that 'withCredentials' is set as a property of the request rather than a header. Instead of using:

headers: {
  Accept: `application/json`,
  'Content-Type': 'application/json',
  withCredentials: true,
},

Modify the client code to:

headers: {
  Accept: `application/json`,
  'Content-Type': 'application/json',
},
withCredentials: true,

The above is the detailed content of Why Is My Browser Rejecting Set-Cookie Headers from Cross-Origin Responses?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn