应该用于发送GZIP COM pressed JSON从Android的客户端到服务器是什么标题? [英] What header should be used for sending GZIP compressed JSON from Android Client to Server?

查看:134
本文介绍了应该用于发送GZIP COM pressed JSON从Android的客户端到服务器是什么标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是扩展的问题<一href="http://stackoverflow.com/questions/11402813/how-to-com$p$pss-a-jsonobject-send-it-over-http-in-android">here.我现在用的是code 这里转载如下,以GZIP COM preSS一个的JSONObject

This question is extension to the question here. I am using the code here reproduced below to GZIP compress a JSONObject.

String foo = "value";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = null;

try {
    gzos = new GZIPOutputStream(baos);
    gzos.write(foo.getBytes("UTF-8"));
} finally {
    if (gzos != null) try { gzos.close(); } catch (IOException ignore) {};
}

byte[] fooGzippedBytes = baos.toByteArray();

我使用的是 DefaultHttpClient 发送此COM pressed的JSONObject到服务器(code是在我的控制)。

I am using a DefaultHttpClient to send this compressed JSONObject to server(the code is in my control).

我的提问

我应该在我的要求用什么标题?我使用 request.setHeader(内容型,应用/ JSON); 发送JSON到服务器

What header should I use in my request? I am using request.setHeader("Content-type", "application/json"); for sending JSON to server?

推荐答案

要通知您发送GZIP恩codeD数据的服务器,发送的内容编码的头,不是的接受编码

To inform the server that you are sending gzip-encoded data, send the Content-Encoding header, not Accept-Encoding.

这篇关于应该用于发送GZIP COM pressed JSON从Android的客户端到服务器是什么标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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