php post

<html>
<body>

<?php
function HTTP_Post($URL,$cookie) 
{ 

   // parsing the given URL 
$URL_Info=parse_url($URL); 

var_dump($URL_Info);
   // Building referrer 

$referrer="111"; 

   // making string from $data 
//foreach($data as $key=>$value) 
//$values[]="$key=".urlencode($value); 
$file="I:/1/1.wav";
$data_string = file_get_contents($file);

//$data_string="kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"; 

   // Find out which port is needed - if not given use standard (=80) 
if(!isset($URL_Info["port"])) 
$URL_Info["port"]=80; 



$request1="Content-Disposition: form-data;";
$request1.="name=\"test.name\";";
$request1.="opcode=\"transcribe_audio\";";
$request1.="sessionid=\"1\";";
$request1.="tmp_entry_id=\"2222222222222222222\";";
$request1.="filename=\"sssssssss\";";
$request1.="type=\"0\";";
$request1.="time=\"11111111111\";";
$request1.="reqid=\"12345\";";
$request1.="latitude=\"1\";";
$request1.="location=\"1\";";
$request1.="language=\"chinese\";"; // use ThinkIT engine
$request1.="uId=\"1\";";
$request1.="ver=\"1.1-123\";";
$request1.="kId=\"46\";";
$request1.="aId=\"2\";";
$request1.="grammarname=\"city\";";
$request1.="sr=\"11\";\r\n";


$boundary = "----------V2ymHFg03ehbqgZCaKO6jy";
   // building POST-request: 
$request="POST ".$URL_Info["path"]." HTTP/1.1\r\n"; 
$request.="Host: ".$URL_Info["host"]."\r\n"; 
$request.="Referer: $referrer\r\n"; 
$request.="Content-type: multipart/form-data;boundary=".$boundary."\r\n"; 


$data="--".$boundary."\r\n"; 

$data.=$request1; 
$data.="\r\n"; 


$data.=$data_string."\r\n"; 

$data.="--".$boundary."--\r\n";

$request.="Content-length: ".strlen($data)."\r\n"; 
$request.="Connection: close\r\n\r\n"; 
$request.=$data;

echo $request;

$fp = fsockopen($URL_Info["host"],$URL_Info["port"]); 
fputs($fp, $request); 
$result="";
while(!feof($fp)) { 
	$result .= fgets($fp, 1024); 
} 
echo "\r\nsssssss------------".iconv("UTF-8", "GB2312", "$result"); 
fclose($fp); 

   return $result; 
} 


HTTP_Post("http://localhost:8080:/test/up","1");
?>

</body>
</html>

你可能感兴趣的:(post)