POST 请求,Ajax 与 cookie

POST 请求则需要设置RequestHeader告诉后台传递内容的编码方式以及在 send 方法里传入对应的值

xhr.open("POST", url, true);

xhr.setRequestHeader(("Content-Type": "application/x-www-form-urlencoded"));

xhr.send("key1=value1&key2=value2");

Ajax 与 cookie

ajax 会自动带上同源的 cookie,不会带上不同源的 cookie

可以通过前端设置 withCredentials 为 true, 后端设置 Header 的方式让 ajax 自动带上不同源的 cookie,但是这个属性对同源请求没有任何影响。会被自动忽略。

withCredentials | MDN

var xhr = new XMLHttpRequest();

xhr.open("GET", "http://example.com/", true);

xhr.withCredentials = true;

xhr.send(null);

相关推荐
CYY952 天前
OkHttp 和 Retrofit 封装使用
okhttp·retrofit
CYY953 天前
OkHttp 的使用
okhttp
朝星14 天前
Android开发[14]:网络优化之OkHttp
android·okhttp·kotlin
之歆16 天前
Promise 基础技术深度解析:从回调地狱到链式调用
前端·okhttp·promise
之歆16 天前
Ajax 基础技术深度解析:XHR 从入门到跨域
前端·ajax·okhttp
YHHLAI17 天前
Ajax — 异步数据交互
ajax·okhttp·交互
Xaire1 个月前
行行查案例-数据解密-国密s4-webpack打包模块补齐
okhttp
霸道流氓气质1 个月前
Spring AI Ollama 连接超时问题排查与解决:OkHttp 读超时配置全指南
人工智能·spring·okhttp
你觉得脆皮鸡好吃吗1 个月前
XSS渗透 COOKIE
网络·http·okhttp·网络安全学习
彭于晏Yan1 个月前
OkHttp 与 RestTemplate 技术选型对比
java·spring boot·后端·okhttp