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

      

  • 相关阅读:
    使用pod install 出现bad interpreter: No such file or directory
    简单易用且功能丰富的纯Swift下载框架
    Swift主题色顶级解决方案一
    如何基于WKWebView开发一个功能完善的资讯内容页
    关于iPhone X 的适配
    iOS11及Xcode9适配问题汇总
    优豆云
    Mac 网站屏蔽修改
    c语言
    iOS 12 前台通知shouldAlwaysAlertWhileAppIsForeground崩溃问题
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/3422155.html
Copyright © 2020-2023  润新知