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

相关推荐
C182981825752 小时前
HttpURLConnection 是 Apache HttpClient 和 OKHttp 底层吗
okhttp·apache
C1829818257514 小时前
restTemplate/Feign(Spring Cloud)或OKHttp Apache HttpClient 这几个关系与底层实现
spring cloud·okhttp·apache
码到成功>_<2 天前
使用OkHttp实现接口调用
okhttp
maycho1233 天前
裂隙瓦斯模型的Comsol模拟之旅
okhttp
chilavert31810 天前
技术演进中的开发沉思-235 Ajax:动态数据(上)
javascript·ajax·okhttp
灰什么鱼11 天前
OkHttp + Retrofit2 调用第三方接口完整教程(以nomad为例)
java·spring boot·okhttp·retrofit
苏打水com12 天前
第六篇:Day16-18 AJAX进阶+接口对接——实现“前后端数据交互”(对标职场“接口开发”核心需求)
css·okhttp·html·js
漏洞文库-Web安全12 天前
CTFHub XSS通关:XSS-过滤关键词 - 教程
前端·安全·web安全·okhttp·网络安全·ctf·xss
chilavert31813 天前
技术演进中的开发沉思-229 Ajax:Firefox 与 Firebug
javascript·okhttp
chilavert31814 天前
技术演进中的开发沉思-224 Ajax面向对象与框架
javascript·okhttp