PHP如何发送原始HTTP数据包 [英] PHP How To Send Raw HTTP Packet

查看:296
本文介绍了PHP如何发送原始HTTP数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个原始的http数据包发送到网络服务器并收到它的响应,但我找不到办法来做到这一点。我不熟悉套接字和我找到的每个链接使用套接字发送udp数据包。任何帮助都会很棒。

I want to send a raw http packet to a webserver and recieve its response but i cant find out a way to do it. im inexperianced with sockets and every link i find uses sockets to send udp packets. any help would be great.

推荐答案

fsockopen 手册页

<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: www.example.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        echo fgets($fp, 128);
    }
    fclose($fp);
}
?>

与服务器的连接是通过 fsockpen 。 $ out 保存HTTP请求,然后使用 frwite 发送。然后使用 fgets 读取HTTP响应。

The connection to the server is established with fsockpen. $out holds the HTTP request that’s then send with frwite. The HTTP response is then read with fgets.

这篇关于PHP如何发送原始HTTP数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆