我正在尝试在使用PhoneGap Build打包的Angular应用程序中进行登录。
当我在浏览器中运行应用程序时,一切正常,可以使用API调用远程服务器进行登录(因此没有服务器CORS问题)。
当我尝试在PhoneGap应用程序中使用相同的代码时,我从服务器获得404响应
PhoneGap请求/响应
Request URL:http://budget.expectbrilliant.com/auth/local
Request Method:POST
Status Code:404 Not Found404 Not Found
Request Payload
{"email":"ben@cogiva.com","password":"nebjam2n"}
Response Headers
Client-Via:shouldInterceptRequest
浏览器请求/响应:
Request URL:http://budget.expectbrilliant.com/auth/local
Request Method:POST
Status Code:200 OK
Remote Address:46.101.93.76:80
Response Headers
Access-Control-Allow-Origin:*
Connection:keep-alive
Content-Length:184
Content-Type:application/json; charset=utf-8
Date:Sat, 16 Jan 2016 12:50:08 GMT
Vary:Accept-Encoding
X-Powered-By:Express
Request Headers
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJfaWQiOiI1Njg3ZGVkNDExNDZjODhhMDc0ZjRjMjYiLCJpYXQiOjE0NTI5NDg1OTcsImV4cCI6MTQ1Mjk2NjU5N30.cJfVi4YED2qTdE_vlaMacK9-OzCa8s2jN3BtMk2VNIA
Connection:keep-alive
Content-Length:48
Content-Type:application/json; charset=UTF-8
Host:budget.expectbrilliant.com
Origin:http://localhost:9000
Referer:http://localhost:9000/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Request Payload
{email: "ben@cogiva.com", password: "nebjam2n"}
email: "ben@cogiva.com"
password: "nebjam2n"
这是HTTP调用:
login: function(user, callback) {
var cb = callback || angular.noop;
var deferred = $q.defer();
$http.post($rootScope.globalURL + '/auth/local', {
email: user.email,
password: user.password
}).
success(function(data) {
$cookieStore.put('token', data.token);
currentUser = User.get();
deferred.resolve(data);
return cb();
}).
error(function(err) {
this.logout();
deferred.reject(err);
return cb(err);
}.bind(this));
return deferred.promise;
},
我已尝试过其他地方建议的解决方案,但除了404之外无法得到任何回复。
修改
这是我的第一个PhoneGap应用程序,我正在使用PhoneGap Build。我最初的目标是Android 4.4及更高版本(但最终想要iOS版本)。
有什么想法吗?