【问题标题】:Nuxt Proxy changes POST to GET when proxy is set to true当代理设置为 true 时,Nuxt 代理将 POST 更改为 GET
【发布时间】:2019-12-25 04:17:43
【问题描述】:

在我的通用 nuxt 应用程序中,我将代理设置为 true 并重写了我的 url 以避免 CORS 问题。 但是当我将代理设置为 true 时,我所有的发布请求都被更改为获取请求。不明白为什么以及如何配置它来进行这种转换。

这是我的 nuxt.config.js :

 /*
  ** Axios module configuration
  */
  axios: {
    proxy: true
  },
  proxy: {
    '/apicore/': { target: 'http://blablabla.fr', pathRewrite: { '^/apicore/': '' }, changeOrigin: true }
  }

我的电话:

  async createJoueur({ state, dispatch, commit }, data) {
    const URL = '/apicore/joueur'
    await this.$axios
      .post(
        URL,
        data, {
          headers: {
            'Content-Type': 'application/json'
          }
        }
      )
      .then((response) => {
          console.log('JOUEUR LOGGED : ')
          if (response.status === 200) {
          } else {
            console.log('Login failed / Not found')
          }
        }
      )
      .catch((error) => {
        console.log('ERROR')
      })

将此代理设置为 true,我的 post-call 就变成了 get one。 我是否忘记了配置中的某些内容?

感谢您的帮助。

【问题讨论】:

  • 您有没有偶然找到解决方案?我遇到了同样的问题...
  • 同样的问题,想知道如何解决这个问题...@Bruno 的回答没有为我解决

标签: proxy axios nuxt.js


【解决方案1】:

我也遇到了同样的问题!我使用 changeOrigin: false 解决了它。

我知道一定是默认值(Look at changeOrigin session),

但似乎在 nuxtjs 代理实现中,此值默认为 true (Look at Options session)。

【讨论】:

【解决方案2】:

我遇到了同样的问题,在使用 onProxyReq option 进行一些日志记录后,我发现问题出在 Cloudflare 代理,而不是 nuxt 代理。 Cloudflare 将 HTTPS 请求转发到 HTTP,这个 forces POST 请求变成了 GET 请求,这在 301/302 重定向中很常见。

据我所知,无法将 Cloudflare 配置为执行 308 重定向,这不会改变 HTTP 方法/正文。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 2016-04-07
    • 2020-12-09
    • 2011-07-22
    • 1970-01-01
    • 2016-11-18
    • 1970-01-01
    相关资源
    最近更新 更多