如何用PHP只发送POST而不返回值
答案:1 悬赏:0 手机版
解决时间 2021-04-07 15:32
- 提问者网友:嗝是迷路的屁
- 2021-04-06 14:48
如何用PHP只发送POST而不返回值
最佳答案
- 五星知识达人网友:患得患失的劫
- 2021-04-06 16:07
$srv_ip = '192.168.10.188';//你的目标服务地址或频道.
$srv_port = 80;
$url = '/demo/test_query_string.php'; //接收你post的URL具体地址$fp = '';
$resp_str = '';
$errno = 0;
$errstr = '';
$timeout = 10;
$post_str = "username=demo&str=aaaa";//要提交的内容.
//echo $url_str;
if ($srv_ip == '' || $dest_url == ''){
echo('ip or dest url empty
');
}
//echo($srv_ip);
$fp = fsockopen($srv_ip,$srv_port,$errno,$errstr,$timeout);if (!$fp){
echo('fp fail');
}
$content_length = strlen($post_str);
$post_header = "POST $url HTTP/1.1\r\n";
$post_header .= "Content-Type: application/x-www-form-urlencoded\r\n";$post_header .= "User-Agent: MSIE\r\n";
$post_header .= "Host: ".$srv_ip."\r\n";
$post_header .= "Content-Length: ".$content_length."\r\n";$post_header .= "Connection: close\r\n\r\n";$post_header .= $post_str."\r\n\r\n";
fwrite($fp,$post_header);
while(!feof($fp)){
$resp_str .= fgets($fp,512);//返回值放入$resp_str}
fclose($fp);
echo($resp_str);//处理返回值.
//unset ($resp_str);
?>
$srv_port = 80;
$url = '/demo/test_query_string.php'; //接收你post的URL具体地址$fp = '';
$resp_str = '';
$errno = 0;
$errstr = '';
$timeout = 10;
$post_str = "username=demo&str=aaaa";//要提交的内容.
//echo $url_str;
if ($srv_ip == '' || $dest_url == ''){
echo('ip or dest url empty
');
}
//echo($srv_ip);
$fp = fsockopen($srv_ip,$srv_port,$errno,$errstr,$timeout);if (!$fp){
echo('fp fail');
}
$content_length = strlen($post_str);
$post_header = "POST $url HTTP/1.1\r\n";
$post_header .= "Content-Type: application/x-www-form-urlencoded\r\n";$post_header .= "User-Agent: MSIE\r\n";
$post_header .= "Host: ".$srv_ip."\r\n";
$post_header .= "Content-Length: ".$content_length."\r\n";$post_header .= "Connection: close\r\n\r\n";$post_header .= $post_str."\r\n\r\n";
fwrite($fp,$post_header);
while(!feof($fp)){
$resp_str .= fgets($fp,512);//返回值放入$resp_str}
fclose($fp);
echo($resp_str);//处理返回值.
//unset ($resp_str);
?>
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯