-->

使从阵营 - 终极版从本地主机一个HTTP请求(make a HTTP Request from R

2019-10-29 08:16发布

我是新的反应终极版,以及所有我已经做了:

1)激活我的后端服务器(本地主机:5000)

2)采用NPM启动激活我前端服务器(本地主机:8080)

3)我试图通过使用派遣行动

this.props.dispatch({type: ActionTypes.FILE_UPLOAD_REQUEST, email: this.state.email, file: this.state.policyFile});

4)使用阿特拉斯 - 传奇,并调用与调度相关的我的服务功能:

let result = yield call(Atlas.uploadFile, action.email, action.file);

5)定义该函数为:

export const uploadFile = (email, file) => { return fetch(`${BASE_URL}/v1/files/${email}/policies`, { method: 'POST', headers:{} , body: {'file': file} }) .then(response => response.json()) }

之后,我试着在我的反应(即调用调度函数)来运行的功能,它给了我,他们不能发现的行车路线错误。 这是从控制台的错误消息。

Fetch API cannot load https://api-staging.autoarmour.co/v1/files/fakeemail@gmail.com/policies. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 500. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

是的,我没有创建任何减速,只是单纯的功能,将上传文件。 谢谢

Answer 1:

我解决这个问题,WOHOO! 该错误消息表示它不是在后端侧连接的。 你需要确保它连接。 我通过我的终极版连接到我的反应组件解决。 多谢你们

干杯!



文章来源: make a HTTP Request from React-Redux from localhost