如何用PHP自动提交表单内容?

来源:百度知道 编辑:UC知道 时间:2024/06/15 11:52:22
如题,我不想用HTML页面,我想直接用PHP把表单内容全部自动提交,然后获取提交后返回的内容?

可以使用sock函数实现向另外一个URL POST数据,并获取返回的结果,sockopen提交POST数据例:

$sock = fsockopen("localhost", 80, $errno, $errstr, 30);
if (!$sock) die("$errstr ($errno)\n");
$data = "txt=" . urlencode("中") . "&bar=" . urlencode("Value for Bar");
fwrite($sock, "POST /posttest/response.php HTTP/1.0\r\n");
fwrite($sock, "Host: localhost\r\n");
fwrite($sock, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($sock, "Content-length: " . strlen($data) . "\r\n");
fwrite($sock, "Accept: */*\r\n");
fwrite($sock, "\r\n");
fwrite($sock, "$data\r\n");
fwrite($sock, "\r\n");
$headers = "";
while ($str = trim(fgets($sock, 4096)))
$headers .= "$str\n";
echo "\n";
$bo