$value) { if ($key != 's') { $query .= $sep . $key .'=' .urlencode($value); $sep = '&'; $data[$key] = rawurldecode($value); } } //TODO: not necessarily xml! header('Content-type: text/xml'); $aResults = parseContent(sendToHost($url, $port, $method, $path, $data)); foreach($aResults['header'] as $header) { header($header); } echo implode("\n", $aResults['body']); /* * PS: * taken from * http://www.faqts.com/knowledge_base/view.phtml/aid/12039/fid/51 * no apparent license or copyright. * modified to add $port * * sendToHost * ~~~~~~~~~~ * Params: * $host - Just the hostname. No http:// or /path/to/file.html portions * $method - get or post, case-insensitive * $path - The /path/to/file.html part * $data - The query string, without initial question mark * $useragent - If true, 'MSIE' will be sent as the User-Agent (optional) * * Examples: * sendToHost('www.google.com','get','/search','q=php_imlib'); * sendToHost('www.example.com','post','/some_script.cgi', * 'param=First+Param&second=Second+param'); */ function sendToHost($host, $port, $method, $path, $data, $useragent=0) { // Supply a default method of GET if the one passed was empty if (empty($method)) { $method = 'GET'; } $method = strtoupper($method); $fp = fsockopen($host, $port); if (!$fp) { echo 'fsockopen failed
'; return; } if ($method == 'GET') { $path .= '?' . $data; } $header = ''; $body = ''; srand((double)microtime()*1000000); $boundary = "---------------------".substr(md5(rand(0,32000)),0,10); $header .= "$method $path HTTP/1.0\r\n"; $header .= "Host: $host\r\n"; $header .= "Content-type: multipart/form-data, boundary=$boundary\r\n"; // attach post vars foreach($_POST as $index => $value){ // if ($index == 'content') { // $fplog = fopen('C:\\preview.log', 'w'); // fwrite($fplog, $value); // fclose($fp); // } $body .= "--$boundary\r\n"; if (substr($value,0,5) == ' $value ) { if ($index == 'DATA') { //write additional form vars needed for file upload to mapagent $body .= "--$boundary\r\n"; $body .= "Content-Disposition: form-data; name=\"DATANAME\"\r\n"; $body .= "\r\n".$value['name']."\r\n"; $body .= "--$boundary\r\n"; $body .= "Content-Disposition: form-data; name=\"DATALENGTH\"\r\n"; $body .= "\r\n".$_FILES[$index]['size']."\r\n"; $body .= "--$boundary\r\n"; $body .= "Content-Disposition: form-data; name=\"".$index."\"; filename=\"".$_FILES['DATA']['name']."\"\r\n"; $body .= "Content-type: application/octet-stream\r\n"; $body .= "\r\n"; $h = fopen( $_FILES['DATA']['tmp_name'], 'rb'); while (!feof($h)) { $body.= fread($h, 4096); } //$body .= fread($h, filesize($value)); fclose($h); $body .= "\r\n"; } } $body .= "--$boundary--\r\n"; $header .= "Content-length: " . strlen($body) . "\r\n"; $header .= "Connection: close\r\n\r\n"; fputs($fp, $header.$body); $buf = ''; while (!feof($fp)) { $buf .= fgets($fp,4096); } fclose($fp); return $buf; } function parseContent( $r ) { $header = array(); $body = array(); $ar = explode("\n", $r); foreach($ar as $idx => $line) { if (trim($line) == '') { $header = array_slice( $ar, 0, $idx); $body = array_slice( $ar, $idx+1); break; } } // echo $r; // print_r($header); // print_r($body); return array( 'header' => $header, 'body' => $body ); } ?>