CURL vs stream_socket_client

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi there,
I'm not in PHP on a daily basis, but from time to time I get to program a
little in PHP for certain projects.

Recently, I've installed a Magento system... and I've installed a canada
post shipping module for this system.

One thing that seems to be tripping it up is that it's using curl.

curl is attempting to send xml data to canada post's server on port 30000.
The response from canada post's system is always an html page...

I've run a test using stream_socket_client and have gotten it to work, the
canada post's system responds with the corresponding XML data with shipping
info.

I'm wondering if there are any curlopt_ options that should be set that
aren't currently set...
Could be that curl is not sending properly formatted XML.

This is the code I'm running.. very similar to the module:

<?php

try {
          $url = "http://sellonline.canadapost.ca";;
          $port = "30000";
          // omitted the full path for email example
          $filename = "cptest.xml";
          $eparcelRequest = file_get_contents($filename);

echo "Testing connection $url:$port";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_PORT, $port);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
          curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
          curl_setopt($ch, CURLOPT_POST,1);
          curl_setopt($ch, CURLOPT_POSTFIELDS,
"XMLRequest=$eparcelRequest");
          $responseBody = curl_exec($ch);
          $status = curl_getinfo($ch);
          curl_close ($ch);
          echo "<br />Request ended without error";
      } catch (Exception $e) {
          echo "<br />Request ended with error<br/><pre>";
          echo print_r($e,true)."</pre>";
          $responseBody = 'error';
      }
    if ($status['http_code']==200) {
      if (strpos(trim($responseBody), '<?xml')===0) {
        echo "<h1 style=\"color:green\">Passed</h1>";
      }
      else {
        echo "<h1 style=\"color:red\">Failed</h1>";
        echo "Able to communicate but did not receive a valid XML
response<br />";
      }
    }
    else {
      echo "<h1 style=\"color:red\">Failed to connect</h1>";
      echo "Communication error<br />";
    }
    echo "Details:<br /><pre>Response:\n";
    echo htmlspecialchars ( $responseBody)."\n\nStatus\n";
    echo print_r($status,true );
    echo "</pre>"; /* */
?>

The curl_getinfo($ch) returns the following:

(
    [url] => http://sellonline.canadapost.ca
    [content_type] => text/html
    [http_code] => 200
    [header_size] => 206
    [request_size] => 324
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.235005
    [namelookup_time] => 7.4E-5
    [connect_time] => 0.116565
    [pretransfer_time] => 0.116678
    [size_upload] => 0
    [size_download] => 1650
    [speed_download] => 7021
    [speed_upload] => 0
    [download_content_length] => 1650
    [upload_content_length] => 0
    [starttransfer_time] => 0.23497
    [redirect_time] => 0
)

Any ideas?

Thanks!

Yves Arsenault

"Love is the only force capable of transforming an enemy into a friend".
--Martin Luther King, Jr.

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux