hi i am struggling with this... maybe someone else had a similar problem
before...
i have to pass 2 variables: (language) and an (xml query string) using http
POST to a search engine. doing this with a normal html form, the seach
engine returns a nice xml response. yet, when passing the POST vars using
the script below, the server does not give any response, it keeps loading
the page.
the script for posting the variables does work since i tested it, i just
dont know what to look for anymore...
html form:
<form name=SeekEngine method=Post
action="http://www.suedtirol.info/XmlApi/Demo/SeekEngine.get?xx=1">
<input type=hidden name=Language value=IT>
<textarea style="font-size:12px" name="XmlParameters" value="" rows=10
cols=135>
<Parameters>
<Group Value="Bike" />
<HotelComfort Value="A.001.004.000.000;A.001.003.000.000;" />
<HotelComfort Value="A.012.020.015.000;A.012.020.020.000;" />
<Stay CheckIn="12/1/2003" Days="2" Board="4" Bookable="0" />
<Room Qty="1" Persons="2" Type="1" />
<HierarchyID Value=""/>
</Parameters>
</textarea>
<input type=button onclick="SendData(form);" name=sEEKeNGINE
value="Engine.Get">
</form>
php fct:
<?php
//################################################## ########################
#######################
//SIMULATES A (HTTP POST) FORM SUBMISSION
//www.zend.com/zend/spotlight/mimocsumissions.php
//takes 2 parameters: associative array containing data to be sent to
server, DNS or IP of server
//returns $result array with lines of response
function post_it($datastream, $url)
//################################################## ########################
#######################
{
//replace http:// with the empty string, get host, get resource
$url = preg_replace("@^http://@i", "", $url);
$host = substr($url, 0, strpos($url, "/"));
$uri = strstr($url, "/"); // kontakt/formular.php
//construct request body: vars and their values
$reqbody ="";
foreach ($datastream as $key => $val)
{
if (!empty($reqbody))
$reqbody .= "&";
$reqbody .= $key."=".urlencode($val);
}
//construct post request to be sent to server, include size of reqbody
$contentlength = strlen($reqbody);
$reqheader = "POST $uri HTTP/1.1 \r\n";
$reqheader .= "Host: $host\n";
$reqheader .= "User-Agent: PostIt\r\n";
$reqheader .= "Content-Type: application/x-www-form-urlencoded\r\n";
$reqheader .= "Content-Length: $contentlength\r\n\r\n";
$reqheader .= "$reqbody\r\n";
//connect to server, send POST request, read result, close socket
$socket = fsockopen($host, 80, $errno, $errstr);
if (!$socket)
{
$result["errno"] = $errno;
$result["errstr"] = $errstr;
return $result;
}
fputs($socket, $reqheader);
while (!feof($socket))
{
$result[] = fgets($socket, 4096);
}
fclose($socket);
return $result;
}
//################################################## ########################
#######################
?>
any help is very appreciated : )
tom