php Socket表单提交学习一下

<?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);

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值