应该使用什么标头将 GZIP 压缩的 JSON 从 Android 客户端发送到服务器?

编程入门 行业动态 更新时间:2024-10-18 03:35:05
本文介绍了应该使用什么标头将 GZIP 压缩的 JSON 从 Android 客户端发送到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这个问题是问题的延伸这里.我正在使用代码此处复制下面的 GZIP 压缩 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 将此压缩的 JSONObject 发送到服务器(代码在我的控制之下).

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

我的问题

我应该在我的 request 中使用什么标头?我正在使用 request.setHeader("Content-type", "application/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 编码的数据,请发送 Content-Encoding 标头,而不是 接受编码.

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

更多推荐

应该使用什么标头将 GZIP 压缩的 JSON 从 Android 客户端发送到服务器?

本文发布于:2023-11-24 22:50:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627194.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   客户端   服务器   GZIP   标头将

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!