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:
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?
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:
01-22 21:10:56.590: INFO/System.out(4641): ----------------------------------setup
01-22 21:10:56.600: INFO/System.out(4641): ----------------------------------properties
01-22 21:10:56.610: INFO/System.out(4641): ----------------------------------connect
01-22 21:10:57.966: DEBUG/LocationMasfClient(63): getNetworkLocation(): Returning cache location with accuracy 544.0
01-22 21:10:58.066: DEBUG/InetAddress(4641): djura.crabdance.com: 145.116.17.93 (family 2, proto 6)
01-22 21:10:58.684: INFO/System.out(4641): ----------------------------------compress
01-22 21:10:58.684: INFO/System.out(4641): ----------------------------------after compress
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.
01-22 21:10:58.690: INFO/System.out(4641): ---------------------------------prepared zipstream
01-22 21:10:58.990: DEBUG/dalvikvm(4641): GC freed 390 objects / 108560 bytes in 138ms
01-22 21:10:59.300: DEBUG/dalvikvm(4641): GC freed 171 objects / 122248 bytes in 81ms
01-22 21:10:59.320: INFO/dalvikvm-heap(4641): Grow heap (frag case) to 4.621MB for 507920-byte allocation
01-22 21:10:59.430: DEBUG/dalvikvm(4641): GC freed 0 objects / 0 bytes in 102ms
01-22 21:10:59.780: DEBUG/dalvikvm(4641): GC freed 3 objects / 245832 bytes in 99ms
01-22 21:10:59.830: INFO/dalvikvm-heap(4641): Grow heap (frag case) to 5.372MB for 1032208-byte allocation
01-22 21:10:59.940: DEBUG/dalvikvm(4641): GC freed 0 objects / 0 bytes in 107ms
01-22 21:11:00.220: VERBOSE/HistActivity(4641): checksum: 2351594448
01-22 21:11:00.220: INFO/System.out(4641): ----------------------------------receiving response
01-22 21:11:00.310: DEBUG/dalvikvm(4641): GC freed 59 objects / 520680 bytes in 81ms
01-22 21:11:08.980: DEBUG/LocationMasfClient(63): getNetworkLocation(): Returning cache location with accuracy 542.0
01-22 21:11:09.100: DEBUG/dalvikvm(2803): GC freed 11118 objects / 600176 bytes in 141ms
01-22 21:11:44.210: DEBUG/dalvikvm(2803): GC freed 13242 objects / 760032 bytes in 146ms
Code:
URL url = new URL(myApp.getServerURL());
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
//connection properties
System.out.println("----------------------------------properties");
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Connection","Keep-Alive");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
System.out.println("----------------------------------connect");
connection.connect();
//Compress and send request
System.out.println("----------------------------------compress");
DataOutputStream dataStream = new DataOutputStream (connection.getOutputStream());
System.out.println("----------------------------------after compress");
try {
//prepare zip stream
CheckedOutputStream checksum = new CheckedOutputStream(dataStream, new Adler32());
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(checksum));
System.out.println("---------------------------------prepared zipstream");
for (int i=0; i<files.length; i++) {
BufferedInputStream origin = null;
ByteArrayInputStream fi = new ByteArrayInputStream(files[i]);
origin = new BufferedInputStream(fi, BUFFER);
ZipEntry entry = new ZipEntry(filenames[i]);
out.putNextEntry(entry);
byte data[] = new byte[BUFFER];
int count;
while((count = origin.read(data, 0, BUFFER)) != -1) {
out.write(data, 0, count);
}
origin.close();
}
out.close();
Log.v(TAG, "checksum: "+ checksum.getChecksum().getValue());
} catch(Exception e) {
e.printStackTrace();
System.out.println("----------------------------------exception");
}
//Receive response
System.out.println("----------------------------------receiving response");
InputStream inputStream = connection.getInputStream();
System.out.println("----------------------------------receiving response2");