zoukankan      html  css  js  c++  java
  • 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 = "
    ";
    
    
    
    $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);
    

      

  • 相关阅读:
    Python中的sorted函数以及operator.itemgetter函数
    a=a+(a++);b=b+(++b);计算顺序,反汇编
    带基虚类的构造函数执行顺序
    开源系统管理资源大合辑
    linux的LNMP架构介绍、MySQL安装、PHP安装
    lamp下mysql安全加固
    ITSS相关的名词解释
    从苦逼到牛逼,详解Linux运维工程师的打怪升级之路
    Linux 文件系统概览
    Exchange2010批量删除邮件
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/3422155.html
Copyright © 2011-2022 走看看