我有一个表单需要将数据发布到位于同一网络中的服务器。将此数据发布到服务器时,它会返回 ERR_EMPTY_RESPONSE
。
我还尝试使用POSTMAN发布到相同的url
,这种方式似乎有效。
是否是同源策略导致此问题?有什么解决方案可以绕过该政策吗?
注意:无法更改服务器端的任何内容,只能更改客户端
这是我用来发布数据的工厂:
app.factory("SendForm", ["$http", "CONFIG", function($http, CONFIG) {
return {
sendInfo: function(dynamic, user1, user2, user3, user4, user5, fixed, aux, onSuccess, onError, onFinally) {
var url = CONFIG.urlSendForm + "?absolute=" + CONFIG.absolute + "&info" + dynamic + "$dyn=" + user1 + "&info2=" + user2 + "&info3=" + user3 + "&info4=" + user4 + "&info5=" + user5 + "&fixed=" + fixed + "&aux=" + aux;
$http.post(url, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.success(function(response, data) {
console.log("success " + response + data + status);
onSuccess();
}).error(function(response, data, status, headers, config) {
onError(response);
});
}
}
}]);
这是我发布后在 shell 中记录的内容:
OPTIONS http://192.168.5.2:9000/?absolute=1234&info1$dyn=1&info2=1&info3=undefined&info4=undefined&info5=undefined&fixed_info=undefined&aux_info=undefined net::ERR_EMPTY_RESPONSE
最佳答案
你的论证顺序很糟糕
post(url, data, [config]); DOC HERE
更改为
var data = {
dynamic: dynamic,
user1: user1,
user2: user2,
.....
.....
}
var config = {
headers: { 'Content-Type': 'application/x-www-form-urlencoded'}
}
$http.post(CONFIG.urlSendForm, data , config).success(...).error(...);
关于javascript - AngularJS $http.post() : returns ERR_EMPTY_RESPONSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33999299/