file_get_contents.php: Post数据
接收数据:
request_post_result.php 接收经过Post的数据:
更加简洁:
<?php
function Post($url, $post = null)
{
$context = array();
if (is_array($post))
{
ksort($post);
$context['http'] = array
(
'method' => 'POST',
'content' => http_build_query($post, '', '&'),
);
}
return file_get_contents($url, false, stream_context_create($context));
}
$data = array
(
'name' => 'test',
'email' => 'test@gmail.com',
'submit' => 'submit',
);
echo Post('http://localhost/5-5/request_post_result.php', $data);
?>
function Post($url, $post = null)
{
$context = array();
if (is_array($post))
{
ksort($post);
$context['http'] = array
(
'method' => 'POST',
'content' => http_build_query($post, '', '&'),
);
}
return file_get_contents($url, false, stream_context_create($context));
}
$data = array
(
'name' => 'test',
'email' => 'test@gmail.com',
'submit' => 'submit',
);
echo Post('http://localhost/5-5/request_post_result.php', $data);
?>
接收数据:
request_post_result.php 接收经过Post的数据:
<?php
echo $_POST['name'];
echo $_POST['email'];
echo $_POST['submit'];
echo "fdfd";
?>
echo $_POST['name'];
echo $_POST['email'];
echo $_POST['submit'];
echo "fdfd";
?>
更加简洁:
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/1623/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2012-5-7 16:25
评论列表