hugh 的个人博客

忽略的知识点- fetch发送cors请求

1. fetch 发送cors请求

为了让浏览器发送包含凭据的请求(即使是跨域源),要将credentials: 'include'添加到传递给 fetch()方法的init对象。

fetch('https://example.com', {
  credentials: 'include'  
})

 

2. xhr发送cor请求

const invocation = new XMLHttpRequest();
const url = 'http://example.com/';

if (invocation) {
invocation.open('GET', url, true);
invocation.withCredentials = true;
invocation.onreadystatechange = function(){};
invocation.send();
}


标题:忽略的知识点- fetch发送cors请求
作者:hugh0524
地址:https://blog.uproject.cn/articles/2019/07/11/1562843911424.html

0 浏览