Tuesday, October 21, 2008

HTTP Post behavior between a C++ CURL client and IIS running Coldfusion 7 not as good as PHP but still providing the functionality

I found that PHP is way more advance when it comes to parse HTTP post request send towards a web server from a C++ client using CURL. HTTP form data are very handy when you want to send data such as cookie, login, password, files, custom command to fit your own underlying protocol between your client and your server. The test that i performed consisted in posting data using form-data towards a IIS/ColdFusion 7 server script from a C++ Client using CURL and i did the same with IIS/Apache/PHP.

To validate my test i also used wget command line tool to post form data using the follwoing command.

wget-1.11.4b>wget --header="Content-tye:multipart/form-data, boundary=--========00000003640" --post-file=postdata.txt http://www.fullyqualifydomainname.com/post.cfm

where the file postdata.txt is :

Content-Disposition: form-data; name="SessionID"
Content-Type: text/plain
Content-Disposition: form-data; name="UserName"
Content-Type: text/plain
Content-Disposition: form-data; name="UserPassword"
Content-Type: text/plain
Content-Disposition: form-data; name="EOF"
Content-Type: text/plain

The conclusion of my test was that it is not easy to retrieve all post data into an array in one single call in ColdFusion something which is working great and easy to achieve in PHP. Something the coldfusion team should concider for future APIs... !

ColdFusion Script post.cfm

first < has been replace by / and > by \ because google blog text editor is retarded..

/cfset x = GetHttpRequestData()\

/cfsavecontent variable="y"\
/table cellpadding = "2" cellspacing = "2"\
/td\/b\HTTP Request item//b\//td\
/td>/b>Value//b//td\ //tr\
/cfloop collection = #x.headers# item = "http_item"\
/td>#StructFind(x.headers, http_item)#//td\ //cfloop\
/b>http_content --- #x.content#//b\

working post.php script

#begin script

error_log("post.php Enter");

$debug = 1;
$server_request_uri = $_SERVER['REQUEST_URI'];
$server_name = $_SERVER['HTTP_HOST'];
$remote_addr = $_SERVER['REMOTE_ADDR'];
$server_addr = $_SERVER['SERVER_ADDR'];
$server_port = $_SERVER['SERVER_PORT'];
$server_request = $_SERVER['REQUEST_METHOD'];
$server_request_time = $_SERVER['REQUEST_TIME'];
$server_protocol = $_SERVER["SERVER_PROTOCOL"];

error_log("POST $server_request_uri HTTP/1.0");
foreach ($headers as $header_entry=>$header_value)
error_log("$header_entry: $header_value");

#end script


21-Oct-2008 09:15:39]
[21-Oct-2008 09:16:29] post.php Enter
[21-Oct-2008 09:16:29] =============================
[21-Oct-2008 09:16:29]
[21-Oct-2008 09:16:29] POST /post.php HTTP/1.0
[21-Oct-2008 09:16:29] Host: www.fullyqualifydomainname.com
[21-Oct-2008 09:16:29] Content-Length: 655
[21-Oct-2008 09:16:29] Content-Encoding: ISO-8859-1
[21-Oct-2008 09:16:29] Content-Type: multipart/form-data; boundary=========00000024328
[21-Oct-2008 09:16:29] Accept: text/html, *.*
[21-Oct-2008 09:16:29] Expect: 100-continue
[21-Oct-2008 09:16:29] Array
[SessionID] =>
[version] => 1.0
[UserName] => test
[UserPassword] => test
[EOF] => EOF


on the other hand

wget http://www.fullyqualifydomainname.com/download/update.cfm --post-data="UserName=test&UserPassword=test" works fine with ColdFusion 7 and the previous script assuming that you will have to parse UserName=test&UserPassword=test as a ByteArray

No comments: