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

      

  • 相关阅读:
    SQL之CASE WHEN用法详解
    MySQL笔记汇总
    Linux常用命令
    TCP/IP速记
    数据结构和算法速记
    多线程相关概念
    线程安全&Java内存模型
    线程通讯wait&notify
    创建多线程的4种方式
    重写ThreadPoolTaskExecutor
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/3422155.html
Copyright © 2011-2022 走看看