业务是一个列表下载的需求,接口定义是get请求方式,但是参数却要求存在于body。

按要求写好之后

export async function download(params) {
  return request({
    url: `url`,
    method: 'get',
    data: params,
    responseType: 'blob',
  });
}

点击导出,报错,后端排查原因是需要去掉content-type, 查了半天也没有找到去掉content-type的方法

随后在网上看到这段文字大受启发,随要求后端,参数不要存放body,从路径上获取

export async function download(params) {
  return request({
    url: `url`,
    method: 'get',
    params, // 改了这里
    responseType: 'blob',
  });
}

这样就去掉了请求头中的content-type,随下载成功

总结: content-type: 是对请求体中的内容的描述,尽管封装的请求头中没有写content-type,发起请求时content-type都会有默认值, 所以要想去掉content-type  可以尝试将入参不要存放body

仅此记录

更多推荐

关于http请求中的content-type