php-使用fopen的Http发布请求
作者:互联网
在第一个文件-我执行的文件中,我具有以下内容:
<?php
$name = "Julia";
$article = "I like papers";
$url = "http://domain.com/process.php";
$param = array('http' => array(
'method' => 'POST',
'content' => $article
));
$mad = @stream_context_create($param);
$fp = @fopen($url, 'rb', false, $mad);
$response = @stream_get_contents($fp);
echo $response;
?>
在第二个文件http://domain.com/process.php中,我有这个:
<?php
$name = $_POST["name"];
$article = $_POST["content"];
$article = $_POST["article"];
echo $article;
echo $name;
echo "Hello there</br>:\n";
?>
我得到的输出是:
"Hello there"
那么怎么了,如何通过请求传递值$article和$name以及如何将它们提取到文件process.php中?
解决方法:
您在内容部分弄错了,使用http_build_query()构建POST查询.
$param = array( 'http' => array('method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'content' => http_build_query($data)
));
您的发布参数应如下所示,其中输入名称为键
$data['name'] = 'Julia';
$data['article'] = 'I like papers';
我个人将使用curl.
标签:http-post,php 来源: https://codeday.me/bug/20191027/1947107.html