如何使用PHP和Curl发送gzip压缩内容?我阅读了很多关于阅读gzip压缩内容的帖子,但我需要向Web服务发送一个gzip压缩XML请求。
我试过了:
$url = 'http://212.170.xxx.xx/appservices/http/FrontendService';
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, Array (
"Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1" ,
"Content-Encoding: gzip"
) );
curl_setopt ( $ch, CURLOPT_POST, 1 );
$comprimido = gzdeflate( 'xml_request=' .$xmlcontent );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $comprimido );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
$RAWresponse = curl_exec ( $ch );
curl_close ( $ch );
还尝试添加:
curl_setopt ($ch, CURLOPT_ENCODING, '');
和
curl_setopt ($ch, CURLOPT_ENCODING, 'Accept-Encoding: gzip,deflate');
但没有效果