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

fetch post 请求获取参数问题 #1848

Closed
xietongjian opened this issue Jul 15, 2018 · 11 comments
Closed

fetch post 请求获取参数问题 #1848

xietongjian opened this issue Jul 15, 2018 · 11 comments

Comments

@xietongjian
Copy link

1、通过tomcat启动端口(8088)发送请求:

fetch('http://127.0.0.1:8088/portal/api/process/saveSp.jhtml', {
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Accept': 'application/json, text/javascript, */*; q=0.01'
    },
    method: 'POST',
    mode: 'cors',
    body: "taskId=8888888888888"
})

Controller可以获取数据:
_20180715225352

2、通过ant design pro 配置的proxy 启动的端口(8000)Controller获取不到数据

// .roadhogrc.mock.js 文件配置:
export default(noProxy ? {
        ...
        'POST /portal/api/(.*)': 'http://127.0.0.1:8088/portal/api/'
        ...    
}: delay(proxy, 200));
fetch('http://127.0.0.1:8000/...'  省略

_20180715230810
请问怎么解决?

@ant-design-bot
Copy link

Translation of this issue:


fetch post Request to get parameter problem

1. Send the request through the tomcat startup port (8088):

Fetch('http://127.0.0.1:8088/portal/api/process/saveSp.jhtml', {
    Headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Accept': 'application/json, text/javascript, */*; q=0.01'
    },
    Method: 'POST',
    Mode: 'cors',
    Body: "taskId=8888888888888"
})

The Controller can get the data:
_20180715225352

2, the port that is enabled by the proxy configured by ant design pro (8000) Controller cannot get the data.

// .roadhogrc.mock.js file configuration:
Export default(noProxy ? {
        ...
        'POST /portal/api/(.*)': 'http://127.0.0.1:8088/portal/api/'
        ...
}: delay(proxy, 200));
Fetch('http://127.0.0.1:8000/...' omitted

_20180715230810
How can I solve it?

@chenshuai2144
Copy link
Collaborator

我们的 request 默认不是 'Content-Type': 'application/x-www-form-urlencoded',
你可能需要修改一下

@xietongjian
Copy link
Author

改了试过,也没有效果。各种类型都试过了。

@xiaohuoni
Copy link
Member

不知道你用的是哪个版本的,可以考虑是mock和proxy调用顺序引起的问题。

@xietongjian
Copy link
Author

大概是1个月前的版本,mock和proxy调用顺序怎么调整?

@xiaohuoni
Copy link
Member

umijs/umi#492

@xietongjian
Copy link
Author

发现jquery的ajax可以获取到值。

@chenshuai2144
Copy link
Collaborator

那就肯定是 Content-Type

@xietongjian
Copy link
Author

其实就是proxy的问题,这个问题很影响开发,开发的时候不好调试真实数据。
同样的请求,同样的Content-Type配置
http://127.0.0.1:8088/portal/api/process/saveSp.jhtml -- tomcat启动的端口(8088)正常获取参数
http://127.0.0.1:8000/portal/api/process/saveSp.jhtml -- npm run start:no-proxy 启动的端口(8000)获取不到参数

@guoyangyang666
Copy link

这个问题解决了吗?我也遇到了这个问题,用ajax可以用post传参,用antdesignpro里封装的post后台就获取不到前端传入的参数

@kaneruan
Copy link

ant design prop 用了 http-proxy-middleware 插件,而这个插件默认不是代理 body 的

chimurai/http-proxy-middleware#202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants