使用dva/fetch请求时没有把cookie带上,导致每次请求session不一样
浏览器默认请求会带上cookie
GET http://localhost/jinxin/php/api/user/registerSeller HTTP/1.1
Host: localhost
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
Cookie: PHPSESSID=2i3s2tp2p2oddsc8u1643epus3
使用fetc请求时没有把cookie带上导致服务器每次的session不一样,没法判断登录状态
GET http://localhost/jinxin/php/api/user/registerSeller HTTP/1.1
Host: localhost
Connection: keep-alive
Origin: http://localhost:8989
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
Accept: */*
Referer: http://localhost:8989/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
@yunfeit 简单场景欢迎尝试 https://github.com/hbrls/vanilla.js
设置fetch的options就好,我的如下:
const options= { method: "GET",mode: 'cors',credentials: 'include'};//same-origin
我因为用cors,所以credentials设置为include,如果不跨域,那么same-origin就行了。
Most helpful comment
设置fetch的options就好,我的如下:
const options= { method: "GET",mode: 'cors',credentials: 'include'};//same-origin
我因为用cors,所以credentials设置为include,如果不跨域,那么same-origin就行了。