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);
7
  • 5
    Is the response tarred or zipped by any chance?
    – Bilal Akil
    Commented Jun 6, 2015 at 1: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
    Commented Jun 6, 2015 at 1:12
  • 1
    You are explicitly asking for a compressed version of the content (if available) with Accept-Encoding: gzip, deflate
    – CBroe
    Commented Jun 6, 2015 at 1:14
  • stackoverflow.com/questions/8364640/… -- probably have to set an option.. Commented Jun 6, 2015 at 1:15
  • 2
    Try just removing the Accept-Encoding: gzip, deflate header
    – Grokify
    Commented Jun 6, 2015 at 1:23

2 Answers 2

14

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.

-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);
2
  • 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
    Commented Feb 14, 2021 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. Commented Feb 14, 2021 at 12:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.