Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用dva/fetch请求时没有把cookie带上,导致每次请求session不一样 #139

Closed
yunfeit opened this issue Oct 9, 2016 · 3 comments

Comments

@yunfeit
Copy link

yunfeit commented Oct 9, 2016

使用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

@hbrls
Copy link
Contributor

hbrls commented Oct 10, 2016

@yunfeit 简单场景欢迎尝试 https://github.com/hbrls/vanilla.js

@bjwulin
Copy link

bjwulin commented Oct 11, 2016

设置fetch的options就好,我的如下:
const options= { method: "GET",mode: 'cors',credentials: 'include'};//same-origin
我因为用cors,所以credentials设置为include,如果不跨域,那么same-origin就行了。

@sorrycc sorrycc closed this as completed Oct 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants