<?php
//发送请求指定的页面
$file = "1.php";
$filename = "gitignore.txt"; //文件名
$path = "/ServerHttpRange/Test.php"; //路径
$host = "127.0.0.1"; //IP地址
$boundary = "---------------------------" . substr(md5(time()), -12);
$clf = "\r\n";
$postData = "";
$postData .= "--{$boundary}" . $clf; //这里多两个,快弄不懂了
$postData .= "Content-Disposition: form-data; name=\"path\"" . $clf . $clf;
$postData .= "{$filename}" . $clf;
$postData .= "--{$boundary}" . $clf;
$postData .= "Content-Disposition: form-data; name=\"username\"" . $clf . $clf;
$postData .= "xlc" . $clf;
$postData .= "--{$boundary}" . $clf;
$postData .= "Content-Disposition: form-data; name=\"city\"" . $clf . $clf;
$postData .= "北京" . $clf;
$postData .= "--{$boundary}" . $clf;
//现在的
$requre = array();
$requre[] = "POST {$path} HTTP/1.1";
$requre[] = "Host: {$host}:80 ";
$requre[] = "Connection: close";
$requre[] = "Range:200";
$requre[] = "Content-Ranges: bytes 0-200";
$requre[] = "Content-type: multipart/form-data, boundary={$boundary}";
$requre[] = "Content-length: ".strlen($postData) . $clf . $clf; //这里得要两个空格
$requre = implode($clf, $requre);
$requre.=$postData;
以前的
//$postHeader="";
//$postHeader .= "POST {$path} HTTP/1.1" . $clf;
//$postHeader .= "Host: 127.0.0.1:80" . $clf;
//$postHeader .= "Connection: close" . $clf;
这里boundary=后面的字符要比上面的postData中的多个'--'字符,不知道为什么
//$postHeader .= "Content-type: multipart/form-data, boundary={$boundary}" . $clf;
//$postHeader .= "Content-length: " . strlen($postData) . $clf . $clf;
//$postHeader.=$postData;
ini_set('auto_detect_line_endings', 1);
//链接远程服务器
$fp = fsockopen("127.0.0.1", 80);
//发送数据
fputs($fp, $requre);
//显示服务器返回数据
while (!feof($fp)) {
echo fgets($fp);
}
//关闭服务器连接
fclose($fp);