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);

相关推荐
符哥20082 天前
基于 OkHttp+Retrofit 实现 JSON / 表单 / XML/Protobuf 数据格式全解析
okhttp·json·retrofit
XiaoLeisj3 天前
Android 网络编程入门到实战:HttpURLConnection、JSON 处理、OkHttp 与 Retrofit2
android·网络·okhttp·json·gson·retrofit2·jsonobjecy
凯鑫BOSS4 天前
Pbootcms查看详细报错信息
okhttp
vistaup1 个月前
OKHTTP 默认构建包含 android 4.4 的TLS 1.2 以及设备时间不对兼容
android·okhttp
bug-0071 个月前
关于前后端自动携带cookie跨域问题
okhttp
weixin_440784112 个月前
Java线程池工作原理浅析
android·java·开发语言·okhttp·android studio·android runtime
weixin_440784112 个月前
OkHttp使用指南
android·java·okhttp
闻哥1 个月前
从 AJAX 到浏览器渲染:前端底层原理与性能指标全解析
java·前端·spring boot·ajax·okhttp·面试
猿小羽2 个月前
OkHttp vs Retrofit 技术分析报告 - 1769404939594
http·okhttp·retrofit·csdn
AylKfTscDFw2 个月前
EtherCAT总线轴控制,大型非标组装检测设备成熟设备程序,注释非常详细,组合应用日本进口机...
okhttp