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

我封装了一下,为什么请求了两次 #99

Closed
jackluo2012 opened this issue Jul 25, 2018 · 1 comment
Closed

我封装了一下,为什么请求了两次 #99

jackluo2012 opened this issue Jul 25, 2018 · 1 comment

Comments

@jackluo2012
Copy link

`const flyio = require("flyio");
//添加请求拦截器
flyio.interceptors.request.use((request) => {
request.baseURL = baseURL;
//给所有请求添加自定义header
request.headers["X-Tag"] = "flyio";
request.url = request.url + "?beid=3";

//打印出请求体
console.log(request.body);
//终止请求
return request;
});
//添加响应拦截器,响应拦截器会在then/catch处理之前执行
flyio.interceptors.response.use( (response) => {
Toast(response.data.status)
if(response.data.status == 1){
return response.data.result
}
}, (err) => {
console.log(err);
//发生网络错误后会走到这里
//return Promise.resolve("ssss")
}
)

// get
export const _get = (req) => {
return flyio.get(req.url,req.data)
}

// post
export const _post = (req) => {
return flyio.post(req.url, req.data)
}
`
image

@wendux
Copy link
Owner

wendux commented Jul 25, 2018

你的请求是不是夸域的?对于非简单的跨域请求,浏览器都会先发起一次预检请求(options)

:octocat: From gitme Android

@wendux wendux closed this as completed Sep 6, 2018
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

2 participants