<?
function Socket_Connect_HTTP_Post($server, $port, $dir, $file, $data) { if ((substr($dir, -1) != "/") && (substr($file, 0, 1) != "/")) { $dir .= "/"; }
$send_url = str_replace("%2F", "/", rawurlencode(rawurldecode(urldecode($dir . $file)))); $method = "POST";
$http_header_array["ALL"][] = "Accept: */*"; $http_header_array["ALL"][] = "Referer: http://".$server."/"; $http_header_array["ALL"][] = "Accept-Language: en-us,zh-cn"; $http_header_array["ALL"][] = "---------------: ----- -------"; $http_header_array["ALL"][] = "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; $http_header_array["ALL"][] = "Connection: Keep-Alive"; $http_header_array["ALL"][] = "Host: ".$server; $http_header_array["ALL"][] = "urn:po-processor";
/* // $http_header_array["ALL"][] = "Cookie: "; // $http_header_array["GET"][] = "If-Modified-Since: Wed, 17 Dec 2003 11:31:54 GMT"; // $http_header_array["GET"][] = "If-None-Match: 10f047-5b2-3fe03eaa"; */ $http_header_array["POST"][] = "Cache-Control: no-cache"; $http_header_array["POST"][] = "Content-Type: text/xml"; //数据XML格式 $http_header_array["POST"][] = "Content-Length: ".strlen($data); // echo "####################################".$data;
if (is_array($http_header_array["ALL"])) { $http_header_str_all = implode("\r\n", $http_header_array["ALL"]); } if (is_array($http_header_array[$method])) { $http_header_str_all .= "\r\n".implode("\r\n", $http_header_array[$method]); }
$send_all = "POST ".$send_url." HTTP/1.1\r\n".$http_header_str_all."\r\n\r\n"; $send_all .= $data."\r\n\r\n";
// echo "2: ".nl2br($send_all."\n\n\n");
$fp_send = @fsockopen($server, $port, $errno, $errstr ,30); // $times_open++;
if ($fp_send) { $can_rcv = 0; fputs($fp_send, $send_all); stream_set_timeout($fp_send, 120); while(!feof($fp_send)) { $content_t = fgets($fp_send, 1024); if ((trim($content_t) == "") && !$can_rcv) { $can_rcv = 1; $content_t = fgets($fp_send, 1024); //echo $content_t ."@@@@@@@@@@@@@@@\n";
} if ($can_rcv == 1 and strlen($content_t)>5) { $reply_str .= $content_t; }
//echo "**".$content_t."@@".$can_rcv."&&".$reply_str."\n";
} $stream_status = stream_get_meta_data($fp_send); fclose($fp_send); if ($stream_status[timed_out]) { $reply_str = ""; } } return $reply_str; } ?>
|