我正在以下方式打电话。
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
ResponseHandler<String> resonseHandler = new BasicResponseHandler();
HttpPost postMethod = new HttpPost(url);
// JSONObject json = new JSONObject();
// json.put("id", data);
postMethod.setHeader("Content-Type", "application/json");
postMethod.setEntity(new ByteArrayEntity(data.getBytes("UTF8")));
response = httpClient.execute(postMethod, resonseHandler);
Log.v(LOG_TAG, "Connector response:" + response);
但我想发送 gzip ,我该怎么做? 我知道我们可以补充一下:
postMethod.setHeader("Content-Encoding", "gzip");
但如何将字符串转换为 gzip 并发送?