You are here:  » No results after SOAP https curl request


No results after SOAP https curl request

Submitted by tedi on Mon, 2012-04-23 02:04 in

Hi David,

I've hit a wall here. I'm making a https curl request to a webservice using SOAP requests. Data "seems" to come back ok. When I print_r everything is fine and dandy but when I pass it into Magic Parser I'm not getting anything. It's important to note that I'm storing the request in a string. The request comes back with a header that I'm using regex to remove.

I'm also running this within a class with the require and the handler function outside the class.

I've tried a few different things, including writing the response to a separate file with not much luck.

Here's a sample of the code:

<?php
require("lib/MagicParser.php");
 function 
parseSoap($record)
  {
      global 
$records;
    
$records[] = $record;
    
print_r($record);
    print 
$record["COL"];
  }
//class starts here
  //call function starts here
  
$retVal curl_exec($soap_do);
        
// print_r($retVal);
        // $this->log($data);
        
if($retVal === false) {
            
$err 'Curl error: ' curl_error($soap_do);
            throw new 
ExceptionError($err);
        } else {
               
//remove header info
            
$string strstr($retVal'<');
            
// $aResp = simplexml_load_string($string);
        
if(!function_exists('xml_parser_create')) {
            
//print "'xml_parser_create()' function not found!";
            
return array();
        }
        
curl_close($soap_do);
        
$records = array();
        
$data trim($string); // string variable contianing the data to parse
         
$dump MagicParser_parse("string://".$data,"parseSoap","xml|CRMMESSAGE/RESULTSET/ROWS/ROW/COL/");
          echo 
"<pre>";
        
print_r($dump);
        echo 
"</pre>";
?>

That was the latest call I did but I've tried different variations, whether it be to display records, not store magicparser results in a variable, etc etc. I don't get any errors back.

Here's a sample of the xml being returned that I'm feeding in there:

<?xml version="1.0" encoding="UTF-8"?> <CRMMessage language="en_US" currency="USD" isTrustedSAT="false" hostversion="1.00"><RequestCode>GetCustomer</RequestCode><ResponseCode>A</ResponseCode><ResultSet><ResultSetMetaData><RSColumn name="PrimaryPOSRef" type="string" nullable="true">RSColumn name="EmailAddress" type="string" nullable="true"></RSColumn></ResultSetMetaData><Rows><Row id="1480006"><Col>0929200000010013</Col><Col>tedikonda@gmail.com</Col></Row></Rows></ResultSet></CRMMessage>

What's strange is that when I hard code that into a string, it seems to work, but when it's being read directly from the request it's not being processed. That out put however, I'm getting when I do a print_r on the string that comes back from the request.

Thanks for your help.

Tedi

Submitted by support on Mon, 2012-04-23 08:21

Hello Tedi,

Rather than rely upon $string = strstr($retVal, '<'); to remove the header it may be safer to instruct cURL to exclude the header from the return value, which you can do using:

  curl_setopt($soap_do, CURLOPT_HEADER, 0 );

Regarding the call to MagicParser_parse() - the return value is actually TRUE (success) or FALSE (error); so rather than printing the return value, it would be best to use something like:

  if (!MagicParser_parse("string://".$data,"parseSoap","xml|CRMMESSAGE/RESULTSET/ROWS/ROW/COL/"))
  {
    print MagicParser_getErrorMessage();
  }

Any output that you see as a result of the parse would come entirely from within your parseSoap() function .

If still no joy; you mentioned that it works fine when injecting the string directly; so the first debug step I would take would be to print the contents of $data to confirm equivalence to the string that you are testing; so just before the call to MagicParser_parse(), use:

  print "<textarea cols='80' rows='10'>".htmlentities($data)."</textarea>";

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by tedi on Mon, 2012-04-23 21:50

David,

Thank you so much for the quick and prompt response.

I had done the header 0, I was at the point where I was just testing different variations because I had hit a wall :)

When I spit everything out into the textbox as you recommended for debugging, I saw xml tags for the response header being dumped in there (which is strange because I don't see the same thing on print_r or var_dump). Even after removing the header and footer with str_replace, I still get the same issue. I suppose this is an issue on my end since the parsing seems to be working on your side when I feed it a proper string.

Thanks for your help.
Tedi

Submitted by tedi on Tue, 2012-04-24 01:49

So I tested to make sure the xml matches htmlentities and it does. The function returns all ampersands for calling the individual columns. This is my function:

 function parseSoap($record)
 {
    // global $records;
    // $records[] = $record;
    // print_r($record);
    // print $record["COL"];
    // print $record["COL"];
   print $record["CRMMESSAGE"];
    print $record["CRMMESSAGE-LANGUAGE"];
    print $record["CRMMESSAGE-CURRENCY"];
    print $record["CRMMESSAGE-ISTRUSTEDSAT"];
    print $record["CRMMESSAGE-HOSTVERSION"];
    print $record["REQUESTCODE"];
    print $record["RESPONSECODE"];
    print $record["RESULTSET"];
    print $record["RESULTSET/RESULTSETMETADATA"];
    print $record["RESULTSET/RESULTSETMETADATA/RSCOLUMN"];
    print $record["RESULTSET/RESULTSETMETADATA/RSCOLUMN-NAME"];
    print $record["RESULTSET/RESULTSETMETADATA/RSCOLUMN-TYPE"];
    print $record["RESULTSET/RESULTSETMETADATA/RSCOLUMN-NULLABLE"];
    print $record["RESULTSET/ROWS"];
    print $record["RESULTSET/ROWS/ROW"];
    print $record["RESULTSET/ROWS/ROW-ID"];
    print $record["RESULTSET/ROWS/ROW/COL"];
    print_r($record);
}

Submitted by support on Tue, 2012-04-24 08:26

Hello Tedi,

Bear in mind when outputting debug text that in an HTML environment the tags within XML will be parsed - that's the reason for using htmlentities() which makes sure they are displayed litterally; also consider how ampersands are represented in HTML which &amp; - this is also a valid XML entity just to add to the confusion!

One handy way to debug XML responses is actually to output a content-type header to make sure the browser displays the script output as plain text; for example:

<?php
  header
("Content-Type: text/plain");
  
$xml file_get_contents("http://www.example.com/somefeed.xml");
  print 
$xml;
?>

So it may be that you are actually receiving the response you expect, it's just that viewing the output of your script in HTML mode is masking what you actually want to see. Try adding the header() function from the above and see if that makes all the difference.

If not, if you could perhaps put together a test script that makes your SOAP call and extracts the response into a $xml variable, and then if you could email me that script I'll check it out on my test server for you and work out the parser code required...

Hope this helps!
Cheers,
David.
--
MagicParser.com

Submitted by tedi on Wed, 2012-04-25 07:46

David,

Thank you so much for your response! I tried the header thing initially without much success.

I will try to do the latter and send to you. I really appreciate your help!

Cheers,

Tedi