java gzip rest_使用restclient或postman发送gzip数据

如何使用restclient或postman将gzip数据作为身体的一部分发送?我用apache restclient 3.2.2也无法获得响应。我附上图片供参考。使用restclient或postman发送gzip数据

基本上我有一个xml文件,想先将它转换为gzip,然后作为body的一部分发送。

要转换为GZip我使用的在线工具首先将我的xml文件转换为gzip,并将转换的gzip文件作为body的一部分包含在我的restclient中。

我得到以下的java代码和代码,我得到的响应正常。 但无法使其在restclient工具中工作!!

TKs2E.jpg restclient body

URL url = new URL(String.format("%s?tid=%d",

sessionInfo._getMessagesUrl, tpegId));

connection = (HttpURLConnection) url.openConnection();

connection.setRequestMethod("POST");

connection.setRequestProperty("Content-Type",

"application/octet-stream");

connection.setUseCaches(false);

connection.setDoInput(true);

connection.setDoOutput(true);

// Convert XML to initial binary payload.

byte[] bytesToSend = getMessagesRequestXml.getBytes("UTF-8");

String fileName = "C:\\\\Sanjay\\\\Work\\\\17MM\\\\MM17_body.txt";

if (this._outputFilename != null) {

System.out.println(String.format("\nWriting body file '%s'", fileName));

FileOutputStream s = new FileOutputStream(fileName);

s.write(bytesToSend);

s.close();

}

dumpBinary("Original GetMessages request", bytesToSend);

// Optionaly compress

if (this._shouldCompress) {

byte[] gzippedBytes = compressToGzip(bytesToSend);

bytesToSend = gzippedBytes;

dumpBinary("Compressed GetMessages request", bytesToSend);

}

// Optionally encrypt

if (sessionInfo._encryptionKey != null) {

byte[] encryptedBytes = encrypt(bytesToSend, sessionInfo._encryptionKey);

bytesToSend = encryptedBytes;

dumpBinary("Encrypted GetMessages request", bytesToSend);

}

// Send request

System.out.println(String.format("Sending GetMessages Request: %s\n", url.toString()));

DataOutputStream os = new DataOutputStream(

connection.getOutputStream());

os.write(bytesToSend, 0, bytesToSend.length);

os.flush();

os.close();

2015-07-12

sanviri

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值