前端笔试题 | 整理总结 ing | 跨域 + fetch + credentials(携带cookie)
题目:
当前网页 :https://a.com
请求接口:https://api.b.com/data
fetch('https://api.b.com/data', {method: 'POST', // 发起 POST 请求credentials: 'include', // 允许携带 cookieheaders: {'Content-Type': 'application/json'},body: JSON.stringify({ id: 1 })
});
// 预检options 接口返回头 如下:
Access-Control-Allow-Origin: https://a.com
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Credentials: true
选项
A. post请求成功,附上cookie
B. 拦截,cors 错误
C. post 发送给服务器,但浏览器不暴露响应结果给脚本。
D. post 请求成功,不附上cookie
当前网页 即前端,请求接口是后端接口地址,此时跨域了。
常见请求头: https://blog.csdn.net/misstianyun/article/details/143753986
来自 pxx 的秋招选择题3 前端笔试复盘 | 知识点总结-CSDN博客
