Taro: Taro.request()当有header参数时GET请求变成OPTIONS

Created on 17 May 2019  ·  3Comments  ·  Source: NervJS/taro

问题描述
当Taro.request()中有header参数时,method参数为'GET'时不起作用,请求被固定为OPTIONS。

复现步骤

带header参数时

Taro.request({
            url: serverUrl + '/api/base/dict/common/policy_regulation',
            method: 'GET',
            header: {
                'content-type': 'application/json'
            }
        }).then(res => console.log(res.data))
Request URL: http://127.0.0.1:8080/api/base/dict/common/policy_regulation
Request Method: OPTIONS
Status Code: 200 
Remote Address: 127.0.0.1:8080
Referrer Policy: no-referrer-when-downgrade

不带header参数时

Taro.request({
            url: serverUrl + '/api/base/dict/common/policy_regulation',
            method: 'GET'
        }).then(res => console.log(res.data))
Request URL: http://127.0.0.1:8080/api/base/dict/common/policy_regulation
Request Method: GET
Status Code: 200 
Remote Address: 127.0.0.1:8080
Referrer Policy: no-referrer-when-downgrade

期望行为
request method不应该受header参数的影响

报错信息

系统信息

$ taro info
👽 Taro v1.2.26


  Taro CLI 1.2.26 environment info:
    System:
      OS: macOS 10.14.4
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 12.1.0 - /usr/local/bin/node
      Yarn: 1.16.0 - /usr/local/bin/yarn
      npm: 6.9.0 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 1.2.26 => 1.2.26
      @tarojs/components: 1.2.26 => 1.2.26
      @tarojs/plugin-babel: 1.2.26 => 1.2.26
      @tarojs/plugin-csso: 1.2.26 => 1.2.26
      @tarojs/plugin-sass: 1.2.26 => 1.2.26
      @tarojs/plugin-uglifyjs: 1.2.26 => 1.2.26
      @tarojs/router: 1.2.26 => 1.2.26
      @tarojs/taro: 1.2.26 => 1.2.26
      @tarojs/taro-h5: 1.2.26 => 1.2.26
      @tarojs/taro-weapp: 1.2.26 => 1.2.26
      @tarojs/webpack-runner: 1.2.26 => 1.2.26
      eslint-config-taro: 1.2.26 => 1.2.26
      eslint-plugin-taro: 1.2.26 => 1.2.26
      nervjs: 1.3.13 => 1.3.13
  • 操作系统: MacOS 10.14.4
  • Taro 版本 v1.2.26
  • Node.js 版本 v12.1.0
  • 报错平台 h5

补充信息

question

Most helpful comment

OPTIONS 是浏览器行为...

请学习下
简单请求

预查请求

All 3 comments

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

OPTIONS 是浏览器行为...

请学习下
简单请求

预查请求

Hello~

您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

Was this page helpful?
0 / 5 - 0 ratings

Related issues

qilovehua picture qilovehua  ·  3Comments

Zchary-Ma picture Zchary-Ma  ·  3Comments

ruixiu picture ruixiu  ·  3Comments

GreatAuk picture GreatAuk  ·  3Comments

leafchao picture leafchao  ·  3Comments