Ant-design-pro: [问题]设置proxy后,get方法可以正常请求,post请求被转成get,可能的原因是?

Created on 16 Jun 2020  ·  2Comments  ·  Source: ant-design/ant-design-pro

🧐 设置proxy后,get方法可以正常请求,post请求被转成get,可能的原因是?

💻 示例代码

proxy文件中设置了代理,如下:

export default {
  dev: {
    '/v1': {
      target: 'http://192.168.2.46:16000',
      changeOrigin: true,
      pathRewrite: { '^': '' },
      logLevel: 'debug',
    },
  }
};

service中方法如下:

import request from 'umi-request'

export async function editPlan(params: any) {
  return request('/v1/change_plan', {
    method: 'POST',
    params
  })
}

npm run dev运行;
发起post请求后,查看proxy log信息;post请求被转成了get

proxy log信息

[HPM] POST /v1/change_plan?user_id=824&plan_id=1&choice_ids=&choice_values= -> http://192.168.2.46:16000
[HPM] Rewriting path from "/v1/change_plan/?user_id=824&plan_id=1&choice_ids=&choice_values=" to "/v1/change_plan/?user_id=824&plan_id=1&choice_ids=&choice_values="
[HPM] GET /v1/change_plan/?user_id=824&plan_id=1&choice_ids=&choice_values= -> http://192.168.2.46:16000

谢谢

🕵🏻‍♀️ question

Most helpful comment

使用data 参数

export async function editPlan(params: any) {
  return request('/v1/change_plan', {
    method: 'POST',
    data: params
  })
}

All 2 comments

使用data 参数

export async function editPlan(params: any) {
  return request('/v1/change_plan', {
    method: 'POST',
    data: params
  })
}

谢谢@chenliang、@chenshuai2144
上次data传参是和@chenliang 写的一样,官方是对的;但这样也是被转成了get请求
问题是endpoint这里我写成了'/v1/change_plan',后端约定的是'/v1/change_plan/',最后少了'/',这里分享下。

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Yoping picture Yoping  ·  3Comments

zhuanglong picture zhuanglong  ·  3Comments

Jerry-goodboy picture Jerry-goodboy  ·  3Comments

ghost picture ghost  ·  3Comments

renyi818 picture renyi818  ·  3Comments