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

奇怪的请求 bug #13

Open
mowatermelon opened this issue Sep 17, 2021 · 1 comment
Open

奇怪的请求 bug #13

mowatermelon opened this issue Sep 17, 2021 · 1 comment

Comments

@mowatermelon
Copy link
Owner

在使用 request 的时候需要修改 header 参数,结果发布到线上之后,发现请求 非 GET 请求接口都会报错 internet error,最开始以为是 服务端的 egg-security 的问题,各种改配置,加白名单加 origin,结果完全没有作用,然后在前端也加了很多 error handle 结果也是没有效果,完全没有想过是 content-type 的问题,去掉之后就正常了,所有类型接口都可以使用了。

import { request as baseRequest } from 'umi'

export async function request<Response, Params = Record<string, unknown>>({
  path,
  method = 'GET',
  params,
  data,
}: IRequestOptions<Params>): Promise<Response | IResponseOptions<any> | never> {

  const obj = {
    ...
    headers: {
      'Content-Type': 'application/json',
    },
   ...
  }

  const res = await baseRequest(path, obj)

  return res
}
@github-actions
Copy link

感谢小伙伴对本仓库项目的提问建议,我会尽快处理小伙伴的提问建议~
Thank you for your questions about the warehouse project. I will deal with your questions as soon as possible~

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

1 participant