【问题标题】:Gzip Camel requestGzip骆驼请求
【发布时间】:2014-01-03 06:13:15
【问题描述】:

我尝试了很多方法来使用骆驼压缩请求(在 json 中),我们正在使用骆驼调用 REST Web 服务。

请求将在正文中,因为我们在 POST 请求中发送它

我尝试将内容编码添加为 gzip,但它不起作用

我尝试添加一个新的数据格式 gzip 和给,但这些都不起作用。

有什么方法可以对输入请求进行gzip,我们需要调用一个将请求压缩为gzip 的Web 服务。我无法从 google 获得太多支持,请帮助

问候 哈里

【问题讨论】:

    标签: java apache apache-camel


    【解决方案1】:

    我不确定我是否完全理解您的要求。但是,如果您只想压缩您的正文内容,您可以使用GZIPOutputStream 并添加一个值为 gzip 的 Content-Encoding 标头

    String foo = "value";
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    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();
    

    【讨论】:

    猜你喜欢
    • 2014-01-19
    • 2022-01-19
    • 2012-12-01
    • 1970-01-01
    • 2014-02-09
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多