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

无论是否设置header,method会变为OPTIONS,我是post,导致服务端获取不到参数 #21

Closed
alicksnake22 opened this issue Feb 12, 2018 · 5 comments

Comments

@alicksnake22
Copy link

alicksnake22 commented Feb 12, 2018

后来看了下chrome的控制台,发现Content-Type还是application/json;charset=UTF-8,下面是我设置的代码,无法设置成功
`
import flyio from "flyio";

flyio.config.baseURL = URL_API_BASE_DOMAIN

flyio.config.timeout = 10000

flyio.config.withCredentials = true

flyio.config.headers = {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
}
`

@wendux
Copy link
Owner

wendux commented Feb 13, 2018

  1. 如若要用“application/x-www-form-urlencoded"编码格式,文档中有专门说明,请查看文档
  2. 浏览器在发起跨域请求时都会先发起一次预检(OPTIONS)请求, 通过后才会发起真正的请求,这是正常的,详情请参考 https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

@alicksnake22
Copy link
Author

好的,明白了。

@alicksnake22
Copy link
Author

alicksnake22 commented Feb 13, 2018

用了qs然后设置编码格式可以了,如果我希望在拦截器里面用qs转参数的话应该如何做?
config.data = qs.stringify(config.data)无效

@wendux
Copy link
Owner

wendux commented Feb 22, 2018

config.body

@alicksnake22
Copy link
Author

alicksnake22 commented Feb 23, 2018 via email

@wendux wendux closed this as completed Feb 23, 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