2环境之间奇怪的错误 - FORMDATA臭虫以$ HTTP POST(AngularJS - ROR) [英] Weird error between 2 environments - FormData bug with $http POST (AngularJS - RoR)
问题描述
我坚持不一致的错误,当我尝试通过$ HTTP方法提交FORMDATA对象到服务器。当我MacOSX上本地运行的轨道服务器发送的形式,但是当我要么推code到分段(Ubuntu的14.04),或者当我的同事(Xubuntu上)尝试它,有效负载对象为空({})。这里是我的设置:
I am stuck with an inconsistent bug when I try to submit a FormData object to the server via the $http method. The form is sent when I am running the rails server locally on MACOSX but when I either push the code to staging (ubuntu 14.04) or when my coworker (Xubuntu) tries it, the payload object is empty ({}). Here is my setup:
return $http.post(url, parsed.form, self.$headers).then(function(res){
self.$parseResponse(res.data, parsed.attrs);
return self;
});
其中parsed.form是一个充满嵌套的JSON和文件附件和FORMDATA对象
where parsed.form is a FormData object filled with a nested json and file attachments and
self.$headers = { headers:
{
'Content-Type': undefined,
'Accept': 'application/json',
'Content-Transfer-Encoding': 'utf-8',
transformRequest: angular.identity
}
};
安装
鲍尔包:
{
"angular": "1.2.28",
"angular-route": "1.2.28",
"angular-resource": "1.2.28",
"angular-bootstrap": "0.12.0",
"angular-activerecord": "latest",
"angular-devise": "latest",
"angular-mocks": "1.2.28",
"lodash": "latest"
}
让我知道如果你需要更多的信息。
Let me know if you need more information.
更新:
我注意到2请求之间的头一个区别:
I noticed a difference in the headers between the 2 requests:
- 失败的请求:内容类型:text / plain的;字符集= UTF-8
- 后面之一:内容类型:多重/ form-data的
更新2:我使用XMLHtt prequest,而不是现在,它似乎已经解决了这一问题,至少在这个特定的形式,我需要一个文件附件进行测试。所以我猜有什么不对的$ HTTP或我使用它的方式。
Update 2: I am using XMLHttpRequest now instead and it seems to have fixed the problem, at least for this particular form, I need to test it with a file attachment. So I am guessing there is something wrong with $http or the way I am using it.
推荐答案
不知道,但我的Mac + Linux环境之间看到的唯一问题是Mac的文件名是区分的不区分大小写的,而在Linux上他们的区分大小写的
Not sure, but the only issues I've seen between Mac + Linux environments are that Mac filenames are case insensitive whereas on linux they are case sensitive.
在Mac上休息,但在Linux上它可能你有误套管文件名的地方,工作正常。
Its possible you have a miss-cased filename somewhere that is working fine on Mac but breaks on Linux.
这篇关于2环境之间奇怪的错误 - FORMDATA臭虫以$ HTTP POST(AngularJS - ROR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!