Umi: 整理了一下#476 关于请求错误的问题(proxy)

Created on 17 May 2018  ·  10Comments  ·  Source: umijs/umi

476

重现例子 https://github.com/xiaohuoni/umi-proxy-issue
问题表现:

使用proxy

GET 表现正常,先有一个pending,然后请求响应了

POST 没带分号 一直在pending 直到超时

Provisional headers are shown

"Content-type": "application/json; charset=UTF-8"

POST 带分号

"Content-type": "application/json; charset=UTF-8;"

返回数据是

{
"id": 101
}

不使用proxy

POST 带分号

"Content-type": "application/json; charset=UTF-8;"

返回数据是

{
"id": 101
}

POST 没带分号

"Content-type": "application/json; charset=UTF-8"

返回数据是

{
  "title": "foo",
  "body": "bar",
   "userId": 1,
   "id": 101
}

不使用umi

没使用umi,和没使用proxy时表现是一致的,可以查看index.html文件

type(bug)

Most helpful comment

测试后发现是把 mock 提到 proxy 之前引起的,MOCK=none umi dev 后是正常的,考虑把 proxy 放到 mock 之前。

All 10 comments

@superlbr
Here is the report of http packages

  1. suppose config like below
proxy: {
  "/api": {
    "target": "http://api.xxx.com/",
    "changeOrigin": true,
    "pathRewrite": { "^/api" : "" }
  }
}
  1. suppose a post request '/api/user/1' with Content-Type: application/json;charset=UTF-8, usually there'll be two request
    one is '/api/user/1', another is '/user/1' because of proxy
  2. what I found is there is no '/user/1' request
  3. however a request with content-type: multipart/form-data is ok

赞!整理地很细致,我找时间看下这个问题。

这个问题对ANT的upload组件有影响。服务端直接获取不到值了。

upload走的应该是formdata,应该不会有关系吧?

@xiaohuoni 在没升级之前是没有问题的。现在我在服务端直接取不到值了,

测试后发现是把 mock 提到 proxy 之前引起的,MOCK=none umi dev 后是正常的,考虑把 proxy 放到 mock 之前。

没使用umi ,post请求 后台接受不到参数,为null 。没有一直处于pending状态 就是后台接受不到参数

export async function doApprove(params) { // return request(/portal/api/process/saveSp.jhtml?${stringify(params)}); return request('/portal/api/process/saveSp.jhtml', { method: 'POST', body: params, }); }

export default (noProxy ? { // 'GET /portal/(.*)':'http://hometest.chinayasha.com/portal', 'GET /portal/api/(.*)': process.env.NODE_ENV === 'production' ?'http://hometest.chinayasha.com/portal/api/':'http://homedev.chinayasha.com/portal/api/', 'POST /portal/api/(.*)': process.env.NODE_ENV === 'production' ?'http://hometest.chinayasha.com/portal/api/':'http://homedev.chinayasha.com/portal/api/', } : delay(proxy, 200));

` 'POST /portal/api/process/saveSp.jhtml': (req, res) => {
res.send({
code:'1',
msg:'操作成功',
data:{

  }
});

},`

Content-type 分号的也试了 没起作用
请问怎么解决

@xiaohuoni 问一下 没有使用umi, antd 的post请求后台也获取不到参数(也没有pending) 请问什么情况?怎么解决? 是哪个地方代理配置有问题嘛

Was this page helpful?
0 / 5 - 0 ratings