$name         = 'yangheping';
$pwd          = 'yhpadmin';
$phone        = '158********';
$content      = '测试POST\GET发送方式';

//组合提交URL以及参数 (GET方式)
//$http       = 'http://www.ceshi.cc/php/post.php'.'?name='.$name.'&pwd='.$pwd.'&dest='.$phone.'&content='.$content;
//$result     = get_to($http);


//组合提交URL以及参数 (POST方式)
$http       = 'http://www.ceshi.cc/php/post.php';
$var        = 'name='.$name.'&pwd='.$pwd.'&dest='.$phone.'&content='.$content;

$result = post_to($var, $http);

/** * 提交的GET接口 * @param string $http 接口地址 * @return int */ /* function get_to($http) { $context = array( 'http'=>array( 'timeout'=> 20, 'method' => 'GET', 'header' => "Content-type: application/x-www-form-urlencoded\r\n", ) ); $xcontext = stream_context_create($context); $ret = @file_get_contents($http, false, $xcontext); //返回 return $ret; } */ /** * 提交的post接口 * @param array $vars 数据 * @param string $http 接口地址 * @return int */ function post_to($vars, $http){ $context = array( 'http'=>array( 'timeout'=> 20, 'method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n" . "Content-length: " . strlen($vars)."\r\n", 'content'=> $vars ) ); $xcontext = stream_context_create($context); $ret = @file_get_contents($http,false,$xcontext); //返回 return $ret; }

相关文章:

  • 2021-11-19
  • 2022-01-01
  • 2021-08-04
  • 2022-12-23
  • 2021-11-19
  • 2021-11-22
猜你喜欢
  • 2022-12-23
  • 2021-10-06
  • 2021-11-19
  • 2021-08-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案