zoukankan      html  css  js  c++  java
  • PHP模拟异步提交

    //$url 异步地址
    //$data 请求数据
    function Fsockopen_Post($url, $data = '')
    {
        $row = parse_MyUrl($url);
        $host = $row['host'];
        $port = isset($row['port']) ? $row['port'] : 80;
        $file = $row['path'];
        $post = '';
        while (list($k,$v) = each($data)) 
        {
            if(isset($k) && isset($v)) $post .= rawurlencode($k)."=".rawurlencode($v)."&"; //转URL标准码
        }
        $post = substr( $post , 0 , -1 );
        $len = strlen($post);
        $fp = @fsockopen( $host ,$port, $errno, $errstr, 10);
        if (!$fp) {
            return "$errstr ($errno)
    ";
        } else {
            $receive = '';
            $out = "POST $file HTTP/1.0
    ";
            $out .= "Host: $host
    ";
            $out .= "Content-type: application/x-www-form-urlencoded
    ";
            $out .= "Connection: Close
    ";
            $out .= "Content-Length: $len
    
    ";
            $out .= $post;    
            fwrite($fp, $out);
            while (!feof($fp)) {
              $receive .= fgets($fp, 128);
            }
            fclose($fp);
            $receive = explode("
    
    ",$receive);
            unset($receive[0]);
            return implode("",$receive);
        }
    }
  • 相关阅读:
    Add Two Numbers
    Same Tree
    Single Number
    题目1190:大整数排序
    题目1182:统计单词
    题目1181:遍历链表
    题目1180:对称矩阵
    题目1179:阶乘
    题目1206:字符串连接
    HTML事件
  • 原文地址:https://www.cnblogs.com/notesbooks/p/10259660.html
Copyright © 2011-2022 走看看