<?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" } "
最后修改:2022 年 07 月 11 日
如果觉得我的文章对你有用,请随意赞赏