Hey all, after some happy hacking...I appear to have been able to get this working from a command line call like this...
C:\PHP_TESTS>php testcalltoZohoCreatorForm.php
...the PHP seems to work OK whether from a Windows (XAMPP PHP) or Linux environment.
Being able to do this is useful if, say, you ever need to schedule some activity, such as a nightly or hourly data transfer from one server to another.
Thanks to some other forum posts, I was able to get this working from a HTML form (i.e. webpage)...and I was able to use this knowledge to have a crack at the command line version...this forum post is here...
Hope this is helpful to someone else...I always felt the Zoho documentation could have included something like this.
- <?php
- //
- // This generic function does the 'hard work' of opening sockets
- // and packing the POST array
- //
- function postit($host, $url, $postdata) {
- $fp = pfsockopen ( $host, 80, &$errno, &$errstr, 60 );
- if( ! $fp ) return "$errstr ($errno)\n";
- fputs ($fp,"POST $url HTTP/1.1\n");
- fputs ($fp,"Host: $host\n");
- fputs ($fp,"User-Agent: Autopost demonstration script\n");
- fputs ($fp,"Accept: */*\n");
- fputs ($fp,"Content-type: application/x-www-form-urlencoded\n");
- fputs ($fp,"Content-length: ".strlen($postdata)."\n\n");
- fputs ($fp,"$postdata\n\n");
- $output = "";
- while( !feof( $fp ) ) {
- $output .= fgets( $fp, 1024);
- }
- fclose ( $fp);
- return ($output);
- }
- $xmlstringdata = "<ZohoCreator><applicationlist><application name=\"sfit-email-templates\"><formlist><form name=\"Post_Method_Receiver_Test\"><add><field name=\"Task\"><value>liamsTestFROMPHPCLI</value></field><field name=\"Description\"><value>liamsTestDescrFROMPHPCLI</value></field></add></form></formlist></application></applicationlist></ZohoCreator>";
- $host = "creator.zoho.com";
- $url = "/api/xml/write/apikey=95653c2e0ae139f785a81arf4bdc44a3&ticket=87b35c49122344c6059a132347266e7112";
- $postdata = "XMLString=$xmlstringdata&zc_ownername=liamzoho2";
- $gotten = postit($host, $url, $postdata);
- # You'll get back all the headers, a blank line and then
- # the content .... this test displays it for all to see!
- $real = htmlspecialchars($gotten);
- $sayurl = "http://$host$url";
- echo "In an echo statement now - $real";
- echo "In an echo statement now - $sayurl";
- echo "In an echo statement now - $postdata";
- ?>