如何利用http来发送post请求

服务器接收:php

<?php服务器

    error_reporting(0);
    function get_contents_input()
    {
        $data = file_get_contents('php://input');     //读取文档流中的数据
        @ file_put_contents('./data/a.txt', $data);   //写入文件中
    }
    get_contents_input();
?>app

 

客服端请求: url

<?php
    
    $data = file_get_contents('./data/b.txt');
     $http_entity_body = $data; 
     $http_entity_type = 'application/x-www-form-urlencoded'; 
     $http_entity_length = strlen($http_entity_body); 
     $host = '127.0.0.1'; 
     $port = 8080; 
     $path = '/20160825/test13.php'; 
    
    
    $fp = fsockopen($host, $port, $error_no, $error_desc, 30);   //建立链接
    if($fp)
    {code

        /**orm

        * 发送头信息文档

        */    
        fputs($fp, "POST {$path} HTTP/1.1\r\n"); 
        fputs($fp, "Host: {$host}\r\n"); 
        fputs($fp, "Content-Type: {$http_entity_type}\r\n"); 
        fputs($fp, "Content-Length: {$http_entity_length}\r\n"); 
        fputs($fp, "Connection: close\r\n\r\n"); 
        fputs($fp, $http_entity_body . "\r\n\r\n"); 
         get

        //读取返回信息
        while (!feof($fp)) { 
         $d .= fgets($fp, 4096); 
        } 
        fclose($fp); 
        echo $d; 
        
    }input

?>it

相关文章
相关标签/搜索