How to send the cookie of localhost to the server

as the title

develop on the local server localhost and interact with the api provided by the online server.

the domain cookie that saves the login token is what localhost, wants to send the cookie to the online server .a.com.

A lot of methods have been found on the Internet, but they can"t achieve their goals.

the following is the related code
clipboard.png
httpcookie
clipboard.png
http

clipboard.png

also ask the bosses for advice

Mar.01,2021

cookie is not allowed to transfer across domains, so cross-domain cookie is not automatically added to the request.
you can first get the local cookie, then add it to the request, and then send it together

< H1 > modify once < / H1 > For

fetch, cookie is not sent by default. You can modify request.credentials to bring cookie

. The credentials read-only attribute Request of the
interface indicates whether the user agent should send cookie if a cookie from another domain sends a cross-domain request. This is similar to XHR's withCredentials flag, but has three available values (instead of two):
omit: never sends cookie (the default).
same-origin: sends user credentials (cookie, basic http authentication, etc.) if the URL is in the same source as the calling script.
include: always sends user credentials (cookie, basic http authentication, etc.), even if it is a cross-source call.
fetch(url, {credentials: 'include'})
< H1 > second modification < / H1 >

when I use this method, I can bring the cookie request

.
    fetch('url', {
        method: 'post',
        credentials: 'include'
    })

Request.credentials

Menu