Dear Clients,
To improve transfer speed and bandwidth utilization, PAPI data will be compressed. Starting January 1, 2020, we will start delivering compressed data using Gzip.
GET request methods that do not request compressed data will receive an error code.
Please make the following update to your Partner API requests (add an “Accept-Encoding” header with value: “gzip”, and decompress the gzipped response):
var request = require('request'), zlib = require('zlib');
var headers = {
'Accept-Encoding': 'gzip' /* Request gzip data response */
};
request({url:'http://localhost:8000/', 'headers': headers})
.pipe(zlib.createGunzip()) /* Decompress gzip data */
.pipe(process.stdout);
import http.client
import json
conn = http.client.HTTPSConnection('www.httpbin.org')
headers = {
'Content-type': 'application/json',
'Accept-Encoding': 'gzip' /* Request gzip data response */
}
json_data = {'text': 'Lorem Ipsum'}
json_file = json.dumps(json_data)
conn.request('POST', '/post', json_file, headers)
response = conn.getresponse()
data = gzip.decompress(response.read()) /* Decompress gzip data */
data = str(data,'utf-8')
print(data.decode())
URL url = new URL("http://example.com");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept-Encoding", "gzip"); /* Request gzip data response */
connection.connect();
InputStream inputStream = connection.getInputStream();
try (final GZIPInputStream gzipInput = new GZIPInputStream(new ByteArrayInputStream(inputStream));
final StringWriter stringWriter = new StringWriter()) {
IOUtils.copy(gzipInput, stringWriter, UTF_8); /* Decompress gzip data */
return stringWriter.toString();
} catch (IOException e) {
throw new UncheckedIOException("Error while decompression!", e);
}
public string GetUrl(string Url, string PostData, bool GZip)
{
HttpWebRequest Http = (HttpWebRequest)WebRequest.Create(Url);
if (GZip)
Http.Headers.Add(HttpRequestHeader.AcceptEncoding, “gzip,deflate”);
/* Request gzip data response */
if (!string.IsNullOrEmpty(PostData))
{
Http.Method = "POST";
byte[] lbPostBuffer = Encoding.Default.GetBytes(PostData);
Http.ContentLength = lbPostBuffer.Length;
Stream PostStream = Http.GetRequestStream();
PostStream.Write(lbPostBuffer, 0, lbPostBuffer.Length);
PostStream.Close();
}
HttpWebResponse WebResponse = (HttpWebResponse)Http.GetResponse();
Stream responseStream = responseStream = WebResponse.GetResponseStream();
if (WebResponse.ContentEncoding.ToLower().Contains("gzip"))
responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
else if (WebResponse.ContentEncoding.ToLower().Contains("deflate"))
responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
/* Decompress gzip data */
StreamReader Reader = new StreamReader(responseStream, Encoding.Default);
string Html = Reader.ReadToEnd();
WebResponse.Close();
responseStream.Close();
return Html;
}
$url = 'http://server.com/path';
$data = array('key1' => 'value1', 'key2' => 'value2');
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => [
'Content-type: application/json',
'Accept-Encoding: gzip' /* Request gzip data response */
],
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$decodedResult = gzdecode($result); /* Decompress gzip data */