【发布时间】:2015-07-19 07:32:27
【问题描述】:
我刚刚更新了 Angular + Ionic 的新版本和处理远程请求的方法停止工作并总是返回 404 响应。
请求如下:
Request Method:POST
Status Code:404 Not Found (from cache)
Request Headersview source
Accept:application/json, text/plain, */*
Content-Type:text/plain
Origin:file://
User-Agent:Mozilla/5.0 (Linux; Android 4.4.2; Lenovo Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36
Request Payloadview source
{,…}
处理远程请求的方法代码如下:
// set transfer credentials
$http({
method : 'POST',
url : $scope.remoteUrl,
data: {img_base64: "/9j/4AAQSkZ"},
headers: 'application/json',
timeout: 10000
// success response
}).success(function(data, status, headers, config) {
//SUCESSS
} else {
//PROCESSING ERROR
}
// error response
}).error(function(data, status, headers, config) {
// ERROR
});
我尝试使用这个主题来解决它:
AngularJs $http.post() does not send data
和
Angular + Ionic Post request getting 404 not found
但没有运气。
服务器端是这样处理请求的:
$inputJSON = file_get_contents('php://input');
$input= json_decode( $inputJSON, TRUE ); //convert JSON into array
如果我尝试使用 Postman 或 Curl 发送请求,一切似乎都正常。
离子信息:
Node Version: v0.12.2
Cordova CLI: 5.0.0
Ionic CLI Version: 1.3.22
Xcode version: Xcode 6.3.1 Build version 6D1002
ios-sim version: Not installed
ios-deploy version: Not installed
AngularJS 版本:
"version": "1.3.13",
请问如何解决?
非常感谢您的建议
【问题讨论】:
标签: javascript ajax angularjs curl