重现例子 https://github.com/xiaohuoni/umi-proxy-issue
问题表现:
Provisional headers are shown
"Content-type": "application/json; charset=UTF-8"
"Content-type": "application/json; charset=UTF-8;"
返回数据是
{
"id": 101
}
"Content-type": "application/json; charset=UTF-8;"
返回数据是
{
"id": 101
}
"Content-type": "application/json; charset=UTF-8"
返回数据是
{
"title": "foo",
"body": "bar",
"userId": 1,
"id": 101
}
没使用umi,和没使用proxy时表现是一致的,可以查看index.html文件
@superlbr
Here is the report of http packages
proxy: {
"/api": {
"target": "http://api.xxx.com/",
"changeOrigin": true,
"pathRewrite": { "^/api" : "" }
}
}
'/api/user/1' with Content-Type: application/json;charset=UTF-8, usually there'll be two request'/api/user/1', another is '/user/1' because of proxy'/user/1' requestcontent-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) 请问什么情况?怎么解决? 是哪个地方代理配置有问题嘛
Most helpful comment
测试后发现是把 mock 提到 proxy 之前引起的,
MOCK=none umi dev后是正常的,考虑把 proxy 放到 mock 之前。