Problem with HTTPpost (but only when using 3G)


Last Updated:

  1. android88

    android88 Member This Topic's Starter

    Joined:
    Jan 6, 2010
    Messages:
    17
    Likes Received:
    0
    Hello everyone. I'm having a weird problem that I hope you guys can help me with before I try to reset my phone to the factory settings. Its a weird problem that seems to have to do with my phone instead of the code, and im hoping that one of you recognizes it, because I have no idea how to fix this.

    I want to send a file (+- 500kb) to a server using httppost, after which i receive a file back. The weird thing is that this exact code used to work on my phone using my 3G connection (vodafone), but now it suddenly stopped working. It still works when I switch my internet connection from 3G to Wifi, so I'm thinking that the problem isn't with the server or the code.

    I know this is a vague description of the problem, but im hoping you recognize it. I was thinking that maybe some setting in my phone (maybe some connection setting) somehow changed which is causing the problems. Or maybe a bad cookie or something like that (if that is possible?)

    The problem also isn't that I don't have any reception, because 3G works fine for browsing and other applications. When I leave my application temporarily to look at the 3G logo, the arrows up and down are both white, so there seems to be stuff going on. The logcat doesn't give an error or anything, it just seems to stop at the line the receives the file back:

    Code (Text):
    1.  
    2. 01-22 21:10:56.590: INFO/System.out(4641): ----------------------------------setup
    3. 01-22 21:10:56.600: INFO/System.out(4641): ----------------------------------properties
    4. 01-22 21:10:56.610: INFO/System.out(4641): ----------------------------------connect
    5. 01-22 21:10:57.966: DEBUG/LocationMasfClient(63): getNetworkLocation(): Returning cache location with accuracy 544.0
    6. 01-22 21:10:58.066: DEBUG/InetAddress(4641): djura.crabdance.com: 145.116.17.93 (family 2, proto 6)
    7. 01-22 21:10:58.684: INFO/System.out(4641): ----------------------------------compress
    8. 01-22 21:10:58.684: INFO/System.out(4641): ----------------------------------after compress
    9. 01-22 21:10:58.690: INFO/global(4641): Default buffer size used in BufferedOutputStream constructor. It would be better to be explicit if an 8k buffer is required.
    10. 01-22 21:10:58.690: INFO/System.out(4641): ---------------------------------prepared zipstream
    11. 01-22 21:10:58.990: DEBUG/dalvikvm(4641): GC freed 390 objects / 108560 bytes in 138ms
    12. 01-22 21:10:59.300: DEBUG/dalvikvm(4641): GC freed 171 objects / 122248 bytes in 81ms
    13. 01-22 21:10:59.320: INFO/dalvikvm-heap(4641): Grow heap (frag case) to 4.621MB for 507920-byte allocation
    14. 01-22 21:10:59.430: DEBUG/dalvikvm(4641): GC freed 0 objects / 0 bytes in 102ms
    15. 01-22 21:10:59.780: DEBUG/dalvikvm(4641): GC freed 3 objects / 245832 bytes in 99ms
    16. 01-22 21:10:59.830: INFO/dalvikvm-heap(4641): Grow heap (frag case) to 5.372MB for 1032208-byte allocation
    17. 01-22 21:10:59.940: DEBUG/dalvikvm(4641): GC freed 0 objects / 0 bytes in 107ms
    18. 01-22 21:11:00.220: VERBOSE/HistActivity(4641): checksum: 2351594448
    19. 01-22 21:11:00.220: INFO/System.out(4641): ----------------------------------receiving response
    20. 01-22 21:11:00.310: DEBUG/dalvikvm(4641): GC freed 59 objects / 520680 bytes in 81ms
    21. 01-22 21:11:08.980: DEBUG/LocationMasfClient(63): getNetworkLocation(): Returning cache location with accuracy 542.0
    22. 01-22 21:11:09.100: DEBUG/dalvikvm(2803): GC freed 11118 objects / 600176 bytes in 141ms
    23. 01-22 21:11:44.210: DEBUG/dalvikvm(2803): GC freed 13242 objects / 760032 bytes in 146ms
    24.  
    25.  
    26.  
    Here is the piece of code where the problem occurs. It only happens when using 3G and not with wifi, and this code used to work fine in the past, so the problem couldnt be with the code right?

    Code (Text):
    1.  
    2.         URL url = new URL(myApp.getServerURL());
    3.         HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    4.        
    5.         //connection properties
    6.         System.out.println("----------------------------------properties");
    7.         connection.setRequestMethod("POST");
    8.         connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    9.         connection.setRequestProperty("Connection","Keep-Alive");
    10.         connection.setUseCaches (false);
    11.         connection.setDoInput(true);
    12.         connection.setDoOutput(true);
    13.         System.out.println("----------------------------------connect");
    14.         connection.connect();
    15.  
    16.         //Compress and send request
    17.         System.out.println("----------------------------------compress");
    18.         DataOutputStream dataStream = new DataOutputStream (connection.getOutputStream());
    19.         System.out.println("----------------------------------after compress");
    20.         try {
    21.  
    22.             //prepare zip stream
    23.             CheckedOutputStream checksum = new CheckedOutputStream(dataStream, new Adler32());
    24.             ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(checksum));
    25.             System.out.println("---------------------------------prepared zipstream");
    26.  
    27.             for (int i=0; i<files.length; i++) {
    28.  
    29.                 BufferedInputStream origin = null;
    30.                 ByteArrayInputStream fi = new ByteArrayInputStream(files[i]);
    31.                 origin = new  BufferedInputStream(fi, BUFFER);
    32.                 ZipEntry entry = new ZipEntry(filenames[i]);
    33.                 out.putNextEntry(entry);
    34.  
    35.                 byte data[] = new byte[BUFFER];
    36.                 int count;
    37.  
    38.                 while((count = origin.read(data, 0, BUFFER)) != -1) {
    39.                     out.write(data, 0, count);
    40.                 }
    41.  
    42.                 origin.close();
    43.             }
    44.  
    45.             out.close();
    46.             Log.v(TAG, "checksum: "+ checksum.getChecksum().getValue());
    47.  
    48.         } catch(Exception e) {
    49.             e.printStackTrace();
    50.             System.out.println("----------------------------------exception");
    51.         }
    52.  
    53.  
    54.  
    55.         //Receive response
    56.         System.out.println("----------------------------------receiving response");
    57.         InputStream inputStream = connection.getInputStream();
    58.         System.out.println("----------------------------------receiving response2");
    59.  
     

    Advertisement
  2. pgalley22

    pgalley22 New Member

    Joined:
    Jan 24, 2010
    Messages:
    2
    Likes Received:
    0
    Hi

    Last week some users one of my applications reported connection troubles when loging into my web server to fetch data.
    After a deeper analysis, it seems that the issue is located around the POST query used for the login. I still not understand why.

    All complains where exclusively coming from users of HTC Magic running on Android 1.6.


    On your side, do you have more information or did you solved this issue ?
    Thanks

    Patrick
     
  3. android88

    android88 Member This Topic's Starter

    Joined:
    Jan 6, 2010
    Messages:
    17
    Likes Received:
    0
    I did not solve it, but I did a speedtest on my 3g and it turns out that it is crazy slow. So I think that caused the problem, because I was uploading an image of reasonable size. Im suspecting my providor restricted my connection because i've been using it too much this month (for testing and stuff)
     
  4. javatai

    javatai New Member

    Joined:
    Jan 19, 2012
    Messages:
    1
    Likes Received:
    0
    Hi,android88:

    check the android source code,
    public BufferedOutputStream(OutputStream out) {
    super(out);
    buf = new byte[8192];

    // BEGIN android-added
    /*
    * For Android, we want to discourage the use of this constructor (with
    * its arguably too-large default), so we note its use in the log. We
    * don't disable it, nor do we alter the default, however, because we
    * still aim to behave compatibly, and the default value, though not
    * documented, is established by convention.
    */
    Logger.global.info(
    "Default buffer size used in BufferedOutputStream " +
    "constructor. It would be " +
    "better to be explicit if an 8k buffer is required.");
    // END android-added
    }

    I think you can find it describe very clear !!

    regards
    anson
     

Share This Page

Loading...