10

I have a problem with my cURL response, when I try to invoke the method of WSDL, I receive this weird text from my browser,

�d�ْ�<�_��[�7�4eS�@���8 �]��Q��A���>�t�,����]�1��%Y���4!l�^ZG��,8��v��������#ZJ�W��
r)0Ek����Q�����"Ᏹ�!�0��0����(�T�$���� Z��փ��UU���g������&�C�f
8�!��5��L�t{����6�?{jY�Q��?���K����3�D2�e   �߱Oc����@^P��$�IΠ�4A[;�p�\7�����i5��+�\歖~=����)�����a�L�GJey�F����Ɍ��v]��<��z������N����\z��.�i:�S5��FgkM�hS���|,\�0�E9i=�+ӄ�!^WҶ�7�����0�w���+b�۹��[�;���fE4_ڑ�������u�Q)E��;�;�JL���������Ԩ�1��7[�$D���\�W���ۂU$9���

How can I solve this?

Here's my header

$headers = array(
                "Accept-Encoding: gzip, deflate",
                "Content-Type: text/xml;charset=\"UTF-8\"",
                "SOAPAction: \"http://tempuri.org/"",
                "Host: domain.com",
                "Content-length: ".strlen($xml_post_string),
                "Connection: Keep-Alive"
                ); 

and here's my curl options

curl_setopt($soap_do, CURLOPT_URL,            $url);
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($soap_do, CURLOPT_TIMEOUT,        120);
curl_setopt($soap_do, CURLOPT_AUTOREFERER,    true); // new
curl_setopt($soap_do, CURLOPT_MAXREDIRS,      10);   // new
curl_setopt($soap_do, CURLOPT_FOLLOWLOCATION, true); // new
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST,           true );            
curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $xml_post_string); 
curl_setopt($soap_do, CURLOPT_VERBOSE,        TRUE); 
curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $headers);
Termininja
  • 6,620
  • 12
  • 48
  • 49
PHP
  • 301
  • 2
  • 12
  • 5
    Is the response tarred or zipped by any chance? – Bilal Akil Jun 06 '15 at 01:10
  • its weird because, yesterday, I just started this code, and I receive a readable text just like, the exact error: "refNo not found" but now, I didn't understand what happen. The respone should be text and human readable only. – PHP Jun 06 '15 at 01:12
  • 1
    You are explicitly _asking_ for a compressed version of the content (if available) with `Accept-Encoding: gzip, deflate` – CBroe Jun 06 '15 at 01:14
  • http://stackoverflow.com/questions/8364640/how-to-properly-handle-a-gzipped-page-when-using-curl -- probably have to set an option.. – user2864740 Jun 06 '15 at 01:15
  • OMG! what do I need to do to make it human readable? – PHP Jun 06 '15 at 01:16
  • Maybe http://stackoverflow.com/questions/22145830/is-there-a-way-to-pass-compressed-into-phps-curl-setopt – user2864740 Jun 06 '15 at 01:19
  • 2
    Try just removing the `Accept-Encoding: gzip, deflate` header – Grokify Jun 06 '15 at 01:23

2 Answers2

13

Thank you guys for your comment, I have solve the issue now, shout out to Grokify, I just remove the Accept-Encoding: gzip, deflate and it is now readable.

PHP
  • 301
  • 2
  • 12
-1

I had a similar problem. Adding working headers (As of my browser) solved it for me.

Current working code of mine:

$headers = array("User-Agent: ********User Agent********");
$ch = curl_init("******URL*******");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$data= curl_exec($ch);
curl_close($ch);
M at
  • 1,020
  • 1
  • 12
  • 26
  • 1
    You've changed a **lot** of headers compared to the ones in the question without justifying the individual changes. The answer from half a decade ago makes the minimal change needed to solve the problem. – Quentin Feb 14 '21 at 10:50
  • Dear @Quentin, I was getting unreadable output from CURL and Adding UserAgent fixed it. Thus I posted it so others reaching this post try this as well, though, you are right this is not a direct answer to the specific scenario in question. – M at Feb 14 '21 at 12:41