Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
xiaohuoni opened this issue May 17, 2018 · 10 comments
Closed

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

xiaohuoni opened this issue May 17, 2018 · 10 comments

Comments

@xiaohuoni
Copy link
Member

xiaohuoni commented May 17, 2018

#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文件

@xiaohuoni
Copy link
Member Author

@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

@sorrycc
Copy link
Member

sorrycc commented May 17, 2018

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

@ghost
Copy link

ghost commented May 18, 2018

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

@xiaohuoni
Copy link
Member Author

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

@ghost
Copy link

ghost commented May 18, 2018

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

@sorrycc
Copy link
Member

sorrycc commented May 20, 2018

相关问题,sorrycc/roadhog#689

@sorrycc sorrycc changed the title 整理了一下#476 关于请求错误的问题 整理了一下#476 关于请求错误的问题(proxy) May 22, 2018
@sorrycc
Copy link
Member

sorrycc commented May 22, 2018

@sorrycc
Copy link
Member

sorrycc commented May 25, 2018

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

@RisingSunYZ
Copy link

RisingSunYZ commented Jul 16, 2018

没使用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 分号的也试了 没起作用
请问怎么解决

@RisingSunYZ
Copy link

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

sorrycc pushed a commit that referenced this issue Jun 23, 2022
* refactor(plugins): 🎨 css related plugin only run in dev or build

* refactor: 🎨 move "if" into onStart hook to make plugin behavior stable

* refactor: 🎨 use onBeforeCompiler instead of onStart

Co-authored-by: pshu <[email protected]>
xierenyuan pushed a commit to xierenyuan/umi that referenced this issue Jun 23, 2022
…js#492)

* refactor(plugins): 🎨 css related plugin only run in dev or build

* refactor: 🎨 move "if" into onStart hook to make plugin behavior stable

* refactor: 🎨 use onBeforeCompiler instead of onStart

Co-authored-by: pshu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants