Have you add the internet permission in manifest like this?
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

? 2011/6/27 11:10, ??? ??:
I use deflater to compress string data. It works fine on java console project, but while running on android enviroment, server will report "buffer error" problem and reture 500.

SendMessage(String content, String url)
{
byte[] bs = deflaterCompress(content);
URL url = new URL(urlStr);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
       httpConn.setDoOutput(true);
       httpConn.setRequestMethod("POST");
       httpConn.setDoInput(true);
//httpConn.setRequestProperty("Content-length", String.valueOf(UmengDeviceHelper.TOTAL_LEN)); httpConn.setRequestProperty("Content-Type", "application/octet-stream");
       httpConn.setRequestProperty("Content-Encoding", "deflate");
       httpConn.connect();
DataOutputStream outputStream = new DataOutputStream(httpConn.getOutputStream());
       outputStream.write(bs);
       //outputStream.write(content.getBytes("utf-8"));
       outputStream.flush();
       outputStream.close();
       int responseCode = 500;
       try {
           responseCode = httpConn.getResponseCode();
           Log.i("MobclickAgent", "reture code is:" + responseCode);
       } catch (NumberFormatException e) {
           // ignore
e.printStackTrace();
       }
}

public static byte[] deflaterCompress(String str) throws IOException
{
byte[] input = str.getBytes(encoding);
byte[] output = new byte[100];
Deflater compresser = new Deflater();
compresser.setInput(input);
compresser.finish();
TOTAL_LEN = compresser.deflate(output);
return output;
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to