Print this page

How can HTTP callouts be compressed and troubleshot?

Knowledge Article Number 000004053
Description

I would like to know how to send compressed HTTP callouts and how to debug compression related issues.

Resolution

Enabling compression

Requests can be compressed to save bandwidth and to reduce the size of the payload of the packets sent over the Internet. To enable callouts compression, use the following code:

HttpRequest req = new HttpRequest();
req.setEndPoint('my_endpoint');
req.setCompressed(true);
req.setBody('some post body');

Note Salesforce only supports compression in Gzip format. Java applications can use Gzipfile stream reader to interpret this format.

Debugging

When a request is sent in compressed format ensure that the following fields are present in the headers:

Content-Encoding: gzip
Accept-Encoding: gzip

To check whether your post request is properly formed,

1) Go to postbin.defensio.com/ and click Create a new PostBin
2) Use the URL obtained as the endpoint of the request.
3) Make a request and check the URL back.
 
To check whether the destination server supports compression, post a request manually using any client, e.g. Poster for Firefox. Send the "Accept-encoding : gzip" request header. If "Accept-encoding : gzip"  is returned in the response then the server supports compression.





promote demote