file_get_contents("php://input")의 사용법

45718 단어 phpphpinput
$data = file_get_contents("php://input");
    php://input                  。 POST       ,     php://input     $HTTP_RAW_POST_DATA,           php.ini   。   ,       $HTTP_RAW_POST_DATA       ,     always_populate_raw_post_data          。 enctype="multipart/form-data"     php://input     。 
    
 
1, php://input     http entity body       , Content-Length    ,   POST    GET         。  ,  GET        ,http request entity body     。 
2,php://input  $HTTP_RAW_POST_DATA         ,    Content-Type  multipart/form-data   。
    
 1Coentent-Type     application/x-www-data-urlencoded multipart/form-dataPHP   http                 $_POST 
 2PHP     Content-Typehttp             $HTTP_RAW_POST_DATA 
 3,   Coentent-Type multipart/form-dataPHP   http             php://input,        。     , Coentent-Length  。 
 4Content-Type application/x-www-data-urlencodedphp://input    $_POST     。 
 5php://input     $HTTP_RAW_POST_DATA  ,  php://input $HTTP_RAW_POST_DATA   ,        php.ini 
 6PHP  PATH   query_path$_GET。     ,GET     httpbody1.php file_get_contents("php://input")  $HTTP_RAW_POST_DATA    xmlgetXML.php;//  XML  
  
php 
     $xmldata = file_get_contents("php://input"); 
     $data = (array)simplexml_load_string($xmldata); 
?> 
 
     $data    xmlphp  xml         
  sendXML.php
 
php 
     $xml = 'xmldata';//    xml 
     $url = 'http://localhost/test/getXML.php';//  XML   
 
     $header = 'Content-type: text/xml';//  content-type xml 
     $ch = curl_init(); //   curl 
     curl_setopt($ch, CURLOPT_URL, $url);//     
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//         
     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//  HTTP  
     curl_setopt($ch, CURLOPT_POST, 1);//   POST   
     curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);//POST   
     $response = curl_exec($ch);//       
     if(curl_errno($ch)){//          
     print curl_error($ch); 
     } 
     curl_close($ch); //  curl   
     echo $response;//       
?> 
 
 2.                
      
   
php 
     //@file phpinput_post.php 
     $data=file_get_contents('btn.png'); 
     $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 = 80; 
     $path = '/image.php'; 
     $fp = fsockopen($host, $port, $error_no, $error_desc, 30); 
     if ($fp){ 
        fputs($fp, "POST {$path} HTTP/1.1\r
"); fputs($fp, "Host: {$host}\r
"); fputs($fp, "Content-Type: {$http_entity_type}\r
"); fputs($fp, "Content-Length: {$http_entity_length}\r
"); fputs($fp, "Connection: close\r
\r
"); fputs($fp, $http_entity_body . "\r
\r
"); while (!feof($fp)) { $d .= fgets($fp, 4096); } fclose($fp); echo $d; } ?> php /** *Recieve image data **/ error_reporting(E_ALL); function get_contents() { $xmlstr= file_get_contents("php://input"); $filename=time().'.png'; if(file_put_contents($filename,$xmlstr)){ echo 'success'; }else{ echo 'failed'; } } get_contents(); ?> 3. HTTP /** * HTTP * @return string */ function get_http_raw() { $raw = ''; // (1) $raw .= $_SERVER['REQUEST_METHOD'].' '.$_SERVER['REQUEST_URI'].' '.$_SERVER['SERVER_PROTOCOL']."\r
"; // (2) Headers foreach($_SERVER as $key => $value) { if(substr($key, 0, 5) === 'HTTP_') { $key = substr($key, 5); $key = str_replace('_', '-', $key); $raw .= $key.': '.$value."\r
"; } } // (3) $raw .= "\r
"; // (4) Body $raw .= file_get_contents('php://input'); return $raw; }

좋은 웹페이지 즐겨찾기