php发送post的问题
程序员文章站
2024-01-14 09:46:34
...
post.php向getPost.php发送post
getPost.php里面只有这句 var_dump($_POST);
为什么getPost.php里面是空 反而post.php里面得到了值。
谢谢了
getPost.php里面只有这句 var_dump($_POST);
为什么getPost.php里面是空 反而post.php里面得到了值。
谢谢了
function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
$postdata = array('name' => 'lichen');
$postdata = http_build_query($postdata);
echo do_post_request('http://localhost/getPost.php', $postdata);
回复内容:
post.php向getPost.php发送post
getPost.php里面只有这句 var_dump($_POST);
为什么getPost.php里面是空 反而post.php里面得到了值。
谢谢了
function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
$postdata = array('name' => 'lichen');
$postdata = http_build_query($postdata);
echo do_post_request('http://localhost/getPost.php', $postdata);
$param请加上'header' => 'Content-type:application/x-www-form-urlencoded'