gpt4 book ai didi

javascript - Aurelia JS 将二进制数据发布到服务器

转载 作者:行者123 更新时间:2023-11-30 15:46:22 24 4
gpt4 key购买 nike

我正在尝试使用 aurelia-fetch-client 将文件发送到服务器,但在浏览器控制台中出现以下错误。 请求的资源上不存在“Access-Control-Allow-Origin” header 。,但是当我对 XMLHttpRequest 执行相同操作时,文件已上传。

Aurelia Fetch Client 配置及使用代码

 activate() {
await fetch;
this.http = this.httpClient();


this.http.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl('http://localhost:3000')
});
}

makeRequest(data) {
this.http.fetch('upload', {
headers: {
'Content-Type': 'multipart/form-data'
},
method: 'post',
body: data
});
}

最佳答案

下面的评论是答案:

服务器上没有启用 CORS,如果您使用的是节点,Ilia 建议使用 cors-express 模块。

以下资源对此有帮助:

http://enable-cors.org/server_expressjs.html

https://github.com/expressjs/cors

关于javascript - Aurelia JS 将二进制数据发布到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40002627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com