<?php $host = 'localhost'; $port = 80; $errno = ''; $errstr = ''; $timeout = 30; $url = '/shiyue/jieshou.php'; $param = array( 'name' => '张三', 'pwd' => '123', ); $data = http_build_query($param); $fp = fsockopen($host, $port, $errno, $errstr, $timeout); if(!$fp){ return false; } $out = "POST ${url} HTTP/1.1\r\n"; $out .= "Host:${host}\r\n"; $out .= "Content-type:application/x-www-form-urlencoded\r\n"; $out .= "Content-length:".strlen($data)."\r\n"; $out .= "Connection:close\r\n\r\n"; $out .= "${data}"; fputs($fp, $out); $response = ''; while($row=fread($fp, 4096)){ $response .= $row; } fclose($fp); $pos = strpos($response, "\r\n\r\n"); $response = substr($response, $pos+4); echo $response;
模拟发送POST请求,提交表单
最新推荐文章于 2023-05-17 16:38:04 发布