<?php
  $data  =  array ( "name"  =>  'test_name' , "content"  =>  'test_con' );
  $data  = http_build_query( $data );
  $opts  =  array (
    'http' => array (
      'method' => "POST" ,
      'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
                "Content-length:" . strlen ( $data ). "\r\n"  .
                "Cookie: foo=bar\r\n"  .
                "\r\n" ,
      'content'  =>  $data ,
    )
  );
  $cxContext  = stream_context_create( $opts );
  $sFile  =  file_get_contents ( "http://127.0.0.1/reponse.php" , false,  $cxContext );  
  echo  $sFile ;
?>

// 结果
string(132) "array(2) { ["content"]=> string(8) "test_con" ["name"]=> string(9) "test_name" } array(1) { ["foo"]=> string(3) "bar" } "
Last modification:July 11th, 2022 at 09:49 am
如果觉得我的文章对你有用,请随意赞赏