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
Release: 2024-11-18 06:30:02
Original
617 people have browsed it

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,
},
Copy after login

Modify the client code to:

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

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template