$data= "username=zhangsan&age=8";
$len =strlen($data);
//print_r($len);die;
$errornu = -1;
$errstr = '';
$url= 'http://localhost/socket/post.php';
$fh = parse_url($url);
//print_r($fh);die;
if(!isset($fh['port'])){
$fh['port'] = 80;
}
$conn = fsockopen($fh['host'],$fh['port'],$errornu,$errstr,3);
//print_r($conn);die;
if(!$conn){
echo " $errstr ( $errnu )
\n" ;
}else{
$post = 'POST '.$fh['path'].' HTTP/1.1'."\r\n";
$post .= 'Host: '.$fh['host']."\r\n";
$post .= 'Content-type: application/x-www-form-urlencoded'."\r\n";
$post .= 'Content-length:'.' '.$len."\r\n";
$post .= ' '."\r\n";
$post .=$data."\r\n";
$post .= ' '."\r\n";
$post .= "Connection: Close\r\n\r\n" ;
//echo $post;die;
fwrite($conn,$post);
while(!feof($conn)){
echo fread ( $conn ,128 );
}
fclose($conn);
}
怎么都是出现 400 的错误,希望大神帮我看看,是怎么回事?