Request: credentials property

Request: credentials property - Web APIs | MDN

The credentials read-only property of the Request interface reflects the value given to the Request() constructor in the credentials option. It determines whether or not the browser sends credentials with the request, as well as whether any Set-Cookie response headers are respected.

Credentials are cookies, TLS client certificates, or authentication headers containing a username and password.

See Including credentials for more details.

Value

A string with one of the following values:

omit

Never send credentials in the request or include credentials in the response.

same-origin

Only send and include credentials for same-origin requests.

include

Always include credentials, even for cross-origin requests.

Examples

In the following snippet, we create a new request using the Request() constructor (for an image file in the same directory as the script), then save the request credentials in a variable:

js
1
2
const request = new Request("flowers.jpg");
const request = request.request; // returns "same-origin" by default

 

调用的例子

import { API_BASE, credentials } from '../routes';

 const result = await fetch(url, {

      method,

      credentials: credentials,

      headers: { ...headers },

      ...data,

    }).

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(6)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示