Re: [PHP] CURL vs stream_socket_client

2009-02-01 Thread Yves Arsenault
Hey there,
First off I'd like to thank the Magento module's author for the support.

The canada post shipping module now works!

The problem was a little bit different then I saw in other posts and forums.

Basically, the curl function wouldn't connect to the
sellonline.canadapost.ca system on the desired port (3).

In the curl section of code, we set opts.. and in the opts... we set the URL
and the port #. For some reason this would not work.


curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, $port);

So what ended up working was to add the port directly to the url and
comment out the port option..

// basically this is what is being passed to the URL opt
$url = 'http://sellonline.canadapost.ca:3';
curl_setopt($ch, CURLOPT_URL, $url);

// and comment out the port opt
//curl_setopt($ch, CURLOPT_PORT, $port);


So, after some diggin' around on curl and great support by module's
author problem solved. Canada Post shipping module now works.
 :)

Yves Arsenault

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


On Fri, Jan 30, 2009 at 4:18 PM, Yves Arsenault wrote:

> Hi all,
> It really seems to me that somehow when the curl command is run that it's
> not posting the request to port 3 to sellonline.canadapost.ca.
>
> That's the impression I'm under.
>
> Any ideas?
>
> Yves Arsenault
>
> "Love is the only force capable of transforming an enemy into a friend".
> --Martin Luther King, Jr.
>
>
> On Fri, Jan 30, 2009 at 12:40 PM, Yves Arsenault  > wrote:
>
>> Hi Todd,
>> First off.. thanks for the reply.
>>
>> I've dumped the xml data and tried to view it in Firefox... commented out
>> the curl code (and all the other stuff) just to see what exactly was getting
>> passed.
>>
>> Firefox did not display it as it does xml... like when I got directly to
>> that xml file with firefox, I get the "This XML file does not appear to have
>> any style information associated with it. The document tree is shown below."
>> (grey bar)... it always shows properly formed xml documents like that for me
>> (collapsible)...
>>
>> But, when I dump it in the PHP script using:
>> print $eparcelRequest;
>>
>> It will just display the values... don't see any collapsible xml tags like
>> when I view the xml directly.
>> So I was thinking it might be in the format sent..
>>
>> I'll try to set the user agent.
>>
>> Thanks!
>> Yves Arsenault
>>
>> "Love is the only force capable of transforming an enemy into a friend".
>> --Martin Luther King, Jr.
>>
>>
>> On Fri, Jan 30, 2009 at 12:19 PM, Boyd, Todd M.  wrote:
>>
>>> > -Original Message-
>>> > From: Yves Arsenault [mailto:yves.arsena...@gmail.com]
>>> > Sent: Friday, January 30, 2009 9:40 AM
>>> > To: PHP List
>>> > Subject: [PHP] CURL vs stream_socket_client
>>> >
>>> > 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
>>> > 3.
>>> > 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 may be a stretch, but try to set the User Agent string to mimic
>>> Firefox before sending your request. I wrote a PHP scrape to gather
>>> guild member information from the World Of Warcraft Armory [1] a few
>>> years back, and it kept giving me HTML instead of XML until I used the
>>> User Agent of a browser that most sites accept is capable of parsing
>>> XML.
>>>
>>> A lot of sites conditionally send IE (and unknown browsers) XHTML
>>> instead of XML if there is any transformation of data involved.
>>>
>>> Also--your comment "Could be that curl is not sending properly formatted
>>> XML" is possible. Have you looked at the resulting HTML that is sent to
>>> curl to make sure that it's not a server error message? If it's the
>>> results you were looking for (but in XHTML format instead of XML), I'll
>>> bet it's a User Agent thing.
>>>
>>> Just a thought...
>>>
>>>
>>> // Todd
>>>
>>
>>
>


Re: [PHP] CURL vs stream_socket_client

2009-01-30 Thread Yves Arsenault
Hi all,
It really seems to me that somehow when the curl command is run that it's
not posting the request to port 3 to sellonline.canadapost.ca.

That's the impression I'm under.

Any ideas?

Yves Arsenault

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


On Fri, Jan 30, 2009 at 12:40 PM, Yves Arsenault
wrote:

> Hi Todd,
> First off.. thanks for the reply.
>
> I've dumped the xml data and tried to view it in Firefox... commented out
> the curl code (and all the other stuff) just to see what exactly was getting
> passed.
>
> Firefox did not display it as it does xml... like when I got directly to
> that xml file with firefox, I get the "This XML file does not appear to have
> any style information associated with it. The document tree is shown below."
> (grey bar)... it always shows properly formed xml documents like that for me
> (collapsible)...
>
> But, when I dump it in the PHP script using:
> print $eparcelRequest;
>
> It will just display the values... don't see any collapsible xml tags like
> when I view the xml directly.
> So I was thinking it might be in the format sent..
>
> I'll try to set the user agent.
>
> Thanks!
> Yves Arsenault
>
> "Love is the only force capable of transforming an enemy into a friend".
> --Martin Luther King, Jr.
>
>
> On Fri, Jan 30, 2009 at 12:19 PM, Boyd, Todd M.  wrote:
>
>> > -----Original Message-
>> > From: Yves Arsenault [mailto:yves.arsena...@gmail.com]
>> > Sent: Friday, January 30, 2009 9:40 AM
>> > To: PHP List
>> > Subject: [PHP] CURL vs stream_socket_client
>> >
>> > 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
>> > 3.
>> > 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 may be a stretch, but try to set the User Agent string to mimic
>> Firefox before sending your request. I wrote a PHP scrape to gather
>> guild member information from the World Of Warcraft Armory [1] a few
>> years back, and it kept giving me HTML instead of XML until I used the
>> User Agent of a browser that most sites accept is capable of parsing
>> XML.
>>
>> A lot of sites conditionally send IE (and unknown browsers) XHTML
>> instead of XML if there is any transformation of data involved.
>>
>> Also--your comment "Could be that curl is not sending properly formatted
>> XML" is possible. Have you looked at the resulting HTML that is sent to
>> curl to make sure that it's not a server error message? If it's the
>> results you were looking for (but in XHTML format instead of XML), I'll
>> bet it's a User Agent thing.
>>
>> Just a thought...
>>
>>
>> // Todd
>>
>
>


Re: [PHP] CURL vs stream_socket_client

2009-01-30 Thread Yves Arsenault
Hi Todd,
First off.. thanks for the reply.

I've dumped the xml data and tried to view it in Firefox... commented out
the curl code (and all the other stuff) just to see what exactly was getting
passed.

Firefox did not display it as it does xml... like when I got directly to
that xml file with firefox, I get the "This XML file does not appear to have
any style information associated with it. The document tree is shown below."
(grey bar)... it always shows properly formed xml documents like that for me
(collapsible)...

But, when I dump it in the PHP script using:
print $eparcelRequest;

It will just display the values... don't see any collapsible xml tags like
when I view the xml directly.
So I was thinking it might be in the format sent..

I'll try to set the user agent.

Thanks!
Yves Arsenault

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


On Fri, Jan 30, 2009 at 12:19 PM, Boyd, Todd M.  wrote:

> > -Original Message-
> > From: Yves Arsenault [mailto:yves.arsena...@gmail.com]
> > Sent: Friday, January 30, 2009 9:40 AM
> > To: PHP List
> > Subject: [PHP] CURL vs stream_socket_client
> >
> > 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
> > 3.
> > 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 may be a stretch, but try to set the User Agent string to mimic
> Firefox before sending your request. I wrote a PHP scrape to gather
> guild member information from the World Of Warcraft Armory [1] a few
> years back, and it kept giving me HTML instead of XML until I used the
> User Agent of a browser that most sites accept is capable of parsing
> XML.
>
> A lot of sites conditionally send IE (and unknown browsers) XHTML
> instead of XML if there is any transformation of data involved.
>
> Also--your comment "Could be that curl is not sending properly formatted
> XML" is possible. Have you looked at the resulting HTML that is sent to
> curl to make sure that it's not a server error message? If it's the
> results you were looking for (but in XHTML format instead of XML), I'll
> bet it's a User Agent thing.
>
> Just a thought...
>
>
> // Todd
>


RE: [PHP] CURL vs stream_socket_client

2009-01-30 Thread Boyd, Todd M.
> -Original Message-
> From: Yves Arsenault [mailto:yves.arsena...@gmail.com]
> Sent: Friday, January 30, 2009 9:40 AM
> To: PHP List
> Subject: [PHP] CURL vs stream_socket_client
> 
> 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
> 3.
> 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 may be a stretch, but try to set the User Agent string to mimic
Firefox before sending your request. I wrote a PHP scrape to gather
guild member information from the World Of Warcraft Armory [1] a few
years back, and it kept giving me HTML instead of XML until I used the
User Agent of a browser that most sites accept is capable of parsing
XML.

A lot of sites conditionally send IE (and unknown browsers) XHTML
instead of XML if there is any transformation of data involved.

Also--your comment "Could be that curl is not sending properly formatted
XML" is possible. Have you looked at the resulting HTML that is sent to
curl to make sure that it's not a server error message? If it's the
results you were looking for (but in XHTML format instead of XML), I'll
bet it's a User Agent thing.

Just a thought...


// Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] CURL vs stream_socket_client

2009-01-30 Thread Yves Arsenault
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 3.
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:

http://sellonline.canadapost.ca";;
  $port = "3";
  // 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 "Request ended without error";
  } catch (Exception $e) {
  echo "Request ended with error";
  echo print_r($e,true)."";
  $responseBody = 'error';
  }
if ($status['http_code']==200) {
  if (strpos(trim($responseBody), 'Passed";
  }
  else {
echo "Failed";
echo "Able to communicate but did not receive a valid XML
response";
  }
}
else {
  echo "Failed to connect";
  echo "Communication error";
}
echo "Details:Response:\n";
echo htmlspecialchars ( $responseBody)."\n\nStatus\n";
echo print_r($status,true );
echo ""; /* */
?>

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.