简体   繁体   English

来自应用的HTTP POST请求在iPhone上有效,但在Android手机上无效

[英]HTTP POST request from app works on iPhone but not on Android phone

In my ionic app I have a POST request to do login. 在我的离子应用程序中,我有一个POST请求来登录。 This works fine on an iPhone but when I test the app on an Android phone the server returns a 404 Not Found error. 这在iPhone上可以正常使用,但是当我在Android手机上测试该应用程序时,服务器返回404 Not Found错误。

My code for making the HTTP request looks like this: 我发出HTTP请求的代码如下:

  loginUser: function(email,password) { var em = email.replace(/\\s/g,''); var pw = password.replace(/\\s/g,''); var url = apiDomain + '/api/v1/user/login/'; if (em && pw) { return $http.post(url, { auth: { email: em, password: pw } }).then(function successCallback(response) { alert('login success. response = '+JSON.stringify(response)); return response; }, function errorCallback(response) { alert('login fail. response = '+JSON.stringify(response)); return -1; }); } }, 

Can anyone think of a reason why this would work on an iPhone but not on an Android phone? 谁能想到为什么它可以在iPhone上运行但不能在Android手机上运行的原因?

The text shown by the alert() in the errorCallback is: errorCallback中alert()所显示的文本是:

 login fail. response = { "data":"", "status":404, "config":{ "method":"POST", "transformRequest":[null], "url":"http://cues-server-dev.elasticbeanstalk.com/api/v1/user/login/", "data":{ "auth":"{ "email":"aa@aa.aa", "password":"alcohol"}}, "headers":{ "Accept":"application/json,text,plain,*/*", "Content-Type":"application/json;charset=utf-8"}}, "statusText":"Not Found"} 

I am at a loss to understand why this works on an iPhone but not an Android phone. 我不知道为什么它可以在iPhone而不是Android手机上工作。

It may be to do with the URL prefix. 可能与URL前缀有关。 Have you tried using: 您是否尝试过使用:

apiDomain = @"https://cues-server-dev.elasticbeanstalk.com"

or 要么

apiDomain = @"http://www.cues-server-dev.elasticbeanstalk.com"

or some other variant. 或其他一些变体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM