2

如何使用 PHP 和 Curl 发送 gzip 压缩的内容?我阅读了很多关于阅读 gzipped 内容的帖子,但我需要将 gzipped XML 请求发送到 Web 服务。

我试过这个:

$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');

但没用

4

0 回答 0