1

I have created php curl to send xml request as under, where it seems that login works. because if there is anything wrong in login detail then it shows error. but if everything is ok then it give response in some garbage value:

Source main code :

$contentlength=strlen($postdata);

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL =>$this->url ,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => "$postdata",
    CURLOPT_HTTPHEADER => array(
        "Content-Type: text/xml;charset=utf-8",        
        "Content-Length: 839",
        "Accept: text/xml",
        "Accept-Encoding: gzip",
        "Authorization : $Authorization",
        "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.11) Gecko/20071204 Ubuntu/7.10 (gutsy) Firefox/2.0.0.11",
        "Host: $host",
        "Connection: close" 

    ),
));

Ouput looks like this :

‹d1oÂ0…÷üŠS–,Û)J›ÈuèÔ"$–²šäH£Æv°MUþ}MÒ€J·»{ŸŸï_}«¾ÐºÖèeÂæ4Ô•©[Ý,““?¤OÉJDÜ¢ëv¸ïLõyåã‡yþ‹ Ç:oñ€6 x

what is wrong ? should i decode anything ? if yes then in which forgat i need to debug. I use securetrading.com site to send xml request.

Haresh Vidja
  • 8,340
  • 3
  • 25
  • 42
user3264863
  • 278
  • 4
  • 15

2 Answers2

1

Simply, you have to remove "Accept-Encoding: gzip" from CURLOPT_HTTPHEADER array.

If still not working, use to decompress output using gzdecode() function

$original_output= gzdecode($curl_output);

For resolve issue of content length you have to count string length of post data, which you have already calculated and stored in $contentlength variable.

"Content-Length:".$contentlength
Haresh Vidja
  • 8,340
  • 3
  • 25
  • 42
  • Now it resolved. But in given docs it is written as under : This kind of error can occur when the Content-Length header is calculated before encoding the XML. The Content-Length header must contain the number of bytes in the actual payload of the request and therefore must be calculated after any character encoding is performed. – user3264863 Sep 21 '16 at 10:07
  • i dont understood it. can you give me just a example as per above my main code ? – user3264863 Sep 21 '16 at 10:07
  • have use first option byr removing header option? or second option by php function? – Haresh Vidja Sep 21 '16 at 10:08
  • also remove "Content-Length: 839" from CURLOPT_HTTPHEADER, it will resolve your error – Haresh Vidja Sep 21 '16 at 10:08
  • we need to pass header so we can not remove it from curl. – user3264863 Sep 21 '16 at 10:09
  • Content-Length is required to send . but at present i have display it static because i dont know that how to calculate it. – user3264863 Sep 21 '16 at 10:09
  • actaully i have to follow this docs http://www.securetrading.com/files/documentation/STPP-Web-Services-User-Guide.pdf where in page 14 it mentiioned what i say. – user3264863 Sep 21 '16 at 10:12
  • I want to know $postdata is string or array? – Haresh Vidja Sep 21 '16 at 10:13
  • i concat string like this $postdata=''; $postdata.=""; $postdata.="X3148177"; – user3264863 Sep 21 '16 at 10:27
  • I have modified my answer please check for content length – Haresh Vidja Sep 21 '16 at 10:28
  • ya i already do it like "Content-Length: $contentlength", but i dont know. it shows error like W5-gqu1vva6 2016-09-21 10:05:20 Malformed XML 10200 Opening and ending tag mismatch: responseblock line 1 and response, line 1, column 716 wkUFPkQ – user3264863 Sep 21 '16 at 10:39
  • as per given docs it says that if there is error in content length then this may happen. If i change content length manually then error change to another TAG name. – user3264863 Sep 21 '16 at 10:39
  • follow this link http://stackoverflow.com/questions/9152165/php-curl-content-length-und-content-type-wrong, it could be help to you,, if you like my answer and helpful to as you asked please mark as correct :) – Haresh Vidja Sep 21 '16 at 10:41
0
curl_setopt($curl, CURLOPT_ENCODING , "gzip");

will show properly the result

CatalinB
  • 571
  • 4
  • 11