PhoneGap上的Ajax请求在2G和3G上更快 [英] Ajax request on PhoneGap faster on 2G then 3G

查看:95
本文介绍了PhoneGap上的Ajax请求在2G和3G上更快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为iOS和Android开发PhoneGap应用程序时,我发现了一个奇怪的行为。



这是265 kb文件的区别:




  • 2G:0m 32s

  • 3G:7m 21s



当然,我运行了一些speedtest( speedtest.net app):




  • 2G:down :〜4kB / s; up:〜2 kB / s

  • 3G:down:〜280 kB / up:〜110 kB / s



这是我在PhoneGap应用程式中的代码:

  // base64编码的图像265kb 
var base64img =data:image / jpeg; base64, 9j / 4AAQSkZJRgABAgAAAQA ...;

$ .ajax({
type:'POST',
url:'http://my.server.nl',
data:{img: encodeURIComponent(base64img)},
dataType:json,
contentType:application / x-www-form-urlencoded; charset = UTF-8
})done结果){
console.log('done:'+ result);
})fail(function(result){
console.log('fail:'+ result);
});

哪位天才能告诉我为什么会发生这种情况?

解决方案

我们终于解决了通过'慢'3G上传内容的问题。



问题真的不同。我们使用沃达丰作为移动运营商,但我们尝试了另一个运营商(* bliep ),运行良好。因此, 是问题。我们发现 Vodafone 正在修改标头。它将连接:关闭更改为连接:Keep-Alive



现在,我们使用SSL(HTTPS)连接,因此 Vodafone 无法更改任何标头。我们在更改为SSL后没有遇到任何问题。


While developing a PhoneGap application for iOS and Android I found a strange behavior. Uploading a file to my server is faster via 2G then 3G.

This are the difference for a 265 kb file:

  • 2G: 0m 32s
  • 3G: 7m 21s

Of course I did run some speedtest (with speedtest.net app) on my iPhone:

  • 2G: down: ~4 kB/s; up: ~2 kB/s
  • 3G: down: ~280 kB/s; up: ~110 kB/s

This is my code in PhoneGap app:

// base64 encoded image of 265kb
var base64img = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAAQA...";

$.ajax({
    type: 'POST',
    url: 'http://my.server.nl',
    data: {img: encodeURIComponent(base64img)},
    dataType: "json",
    contentType: "application/x-www-form-urlencoded;charset=UTF-8"
}).done(function(result){
    console.log('done: ' + result);
}).fail(function(result){
    console.log('fail: ' + result);
});

Which genius can tell me why this is happening?

解决方案

We finally solved the problem for uploading stuff via 'slow' 3G.

The problem really was different. We used Vodafone as mobile operator, but we tried another operator (*bliep) and it was working well. So Vodafone was the problem. We found out that Vodafone was modifying the headers. It changed Connection: close to Connection: Keep-Alive.

Now we using an SSL (HTTPS) connection, so Vodafone can't change any headers. We haven't had any problems after changing to SSL.

这篇关于PhoneGap上的Ajax请求在2G和3G上更快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆