Sending gzip data using restclient or postman

How can I send gzip data as part of body using restclient or postman ?. I was using apache restclient 3.2.2, also couldn't get an answer. I have attached images for reference.

Basically I have an xml file, you want to convert it to gzip first and then send it as part of the body.

To convert to GZip, I used online tools to first convert my xml file to gzip and included the converted gzip file as a body part in my restclient.

I got the following java code and with the code I am getting the answer correctly. But can't get it to work in restclient tool! ! restclient headersbody restclient

    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();

      

+3


source to share


1 answer


I figured out that you need to pass gzip as a file to restclient. This solved my problem.



0


source







All Articles