如何通过curl发送gziped的xml
之前有个项目是通过xml与web service交互的,现在要求发出去的request xml需要gzip压缩
以下是我的代码, 似乎不成功, 提示http500
$headers = array(
'Content-Type: text/xml;charset=UTF-8',
'Content-Encoding: gzip',
);
$gziped_xml_content = gzencode($xml_content);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $the_web_service_url);
curl_setopt($ch, CURLOPT_TIMEOUT,120);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_POSTFIELDS, $gziped_xml_content);
$res = curl_exec($ch);
curl_close($ch);
nico72
11 years, 2 months ago