developer
developer

Reputation: 429

Sending gzip data using restclient or postman

How can I send gzip data as part of body using restclient or postman?. I used apache restclient 3.2.2 also couldn't able to get the response. I have attached images for reference.

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

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

I got following java code and with code I'm getting response properly. But not able to get it working in restclient tool! ! restclient headers 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();

Upvotes: 4

Views: 17929

Answers (1)

developer
developer

Reputation: 429

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

Upvotes: 0

Related Questions