PhoneGap Ajax 请求在使用 AT&T 数据但不在 WiFi 上时返回 502(错误网关)

发布于 2024-12-09 03:29:18 字数 2691 浏览 0 评论 0原文

使用 PhoneGap 制作 iOS 应用程序,我正在做一些非常简单的事情(向远程 API 发出 ajax 请求)。在我的物理设备 (iPhone 4) 上进行测试时,当我使用 WiFi 发出请求时,一切正常,但当我通过 AT&T 数据计划发出请求时,我收到 502 错误网关响应(如下)。我觉得它在 PhoneGap 连接类中,但我可能是错的...我知道我的服务器正在正确接收请求,因为它在任一数据连接上在我的数据库中创建一个实例,这只是在 AT& 上响应被中断;T 数据。

这是我的 AJAX 打印输出和错误参数

$.ajax(
{
  url : 'http://remotehost.com/api/users/login',
  type : 'POST',
  dataType : 'json',
  data : $('#user_login').serializeArray(),
  success : function(result)
  {
  }
});

2011-10-10 00:05:12.983 Emoome[481:707] [INFO] Object:
readyState = 4
setRequestHeader = function (a, b) {t===0&&(l[a.toLowerCase()]=b);return this;}
getAllResponseHeaders = function () {return t===2?m:null;}
getResponseHeader = function (a) {var b;if(t===2){if(!n){n={};while(b=bs.exec(m))n[b[1].toLowerCase()]=b[2]}b=n[a.toLowerCase()]}return b||null;}
abort = function (a) {a=a||"abort",o&&o.abort(a),w(0,a);return this;}
promise = function (a, c) {if(a==null){if(e)return e;e=a={}}c=z.length;while(c--)a[z[c]]=b[z[c]];return a;}
isRejected = function () {return c||b;}
isResolved = function () {return c||b;}
fail = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
done = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
then = function (a, c) {b.done(a).fail(c);return this;}
success = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
error = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
complete = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
statusCode = function (a) {if(a){var b;if(t<2)for(b in a)k[b]=[k[b],a[b]];else b=a[v.status],v.then(b,b)}return this;}
responseText = <html><body><h1>502 Bad Gateway</h1>
    The server returned an invalid or incomplete response.
    </body></html>
    
status = 502
statusText = error

Using PhoneGap to make an iOS app, I am doing something really simple (making an ajax request to a remote API). While testing on my physical device (iPhone 4) Everything works fine when I make my request when using WiFi but when i make my requests over AT&T data plan I get a 502 bad gateway response (below). I feel it is in the PhoneGap connection class but I could could be wrong... I know my server is receiving the request properly as it creating an instance in my database on either data connection, it is just the response is borked while on AT&T data.

Here is my printout of my AJAX and the error param

$.ajax(
{
  url : 'http://remotehost.com/api/users/login',
  type : 'POST',
  dataType : 'json',
  data : $('#user_login').serializeArray(),
  success : function(result)
  {
  }
});

2011-10-10 00:05:12.983 Emoome[481:707] [INFO] Object:
readyState = 4
setRequestHeader = function (a, b) {t===0&&(l[a.toLowerCase()]=b);return this;}
getAllResponseHeaders = function () {return t===2?m:null;}
getResponseHeader = function (a) {var b;if(t===2){if(!n){n={};while(b=bs.exec(m))n[b[1].toLowerCase()]=b[2]}b=n[a.toLowerCase()]}return b||null;}
abort = function (a) {a=a||"abort",o&&o.abort(a),w(0,a);return this;}
promise = function (a, c) {if(a==null){if(e)return e;e=a={}}c=z.length;while(c--)a[z[c]]=b[z[c]];return a;}
isRejected = function () {return c||b;}
isResolved = function () {return c||b;}
fail = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
done = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
then = function (a, c) {b.done(a).fail(c);return this;}
success = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
error = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
complete = function () {if(!e){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=d.type(i),j==="array"?f.done.apply(f,i):j==="function"&&a.push(i);k&&f.resolveWith(k[0],k[1])}return this;}
statusCode = function (a) {if(a){var b;if(t<2)for(b in a)k[b]=[k[b],a[b]];else b=a[v.status],v.then(b,b)}return this;}
responseText = <html><body><h1>502 Bad Gateway</h1>
    The server returned an invalid or incomplete response.
    </body></html>
    
status = 502
statusText = error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╰ゝ天使的微笑 2024-12-16 03:29:18

我终于弄清楚了这个问题。与 AT&T 或 PhoneGap 无关...仍然不确定前者是否不负责,因为 AT&T 是阴暗的...问题实际上出在我的 CodeIgniter REST 服务器中 - 我的应用程序正在创建一个新会话每个登录请求(ajax POST 请求)的条目,不知何故,当通过 AT&T 的线路返回时,我的应用程序确定这是一个 502 错误,因为它没有看到 cookie 或会话数据。

I finally figured out the dang problem. Had nothing to do with AT&T or PhoneGap... well still not exactly sure if the former is not responsible as AT&T is shady... The issue was actually in my CodeIgniter REST server- my app was creating a new session entry for each login request (ajax POST request) and somehow when coming back over AT&T's wire my app was deciding this was a 502 error as it was not seeing the cookie or session data.

烂人 2024-12-16 03:29:18

对于仍然遇到这个问题的人来说,我也遇到了这个问题。当我从应用程序向服务器发送请求时,我有一个 setcookie 函数。

这正是我所拥有的: setcookie('like'.$_POST[qid].'', ​​'1', time() + (60 * 60), "/");

当我删除设置的cookie后,一切工作正常。很奇怪。

For anyone still having this issue, I too was having the issue. When I sent a request to the server from my app, I had a setcookie function.

This was exactly what I had: setcookie('like'.$_POST[qid].'', '1', time() + (60 * 60), "/");

As soon as I removed the set cookie, everything worked fine. Very odd.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文