简单的PHP脚本向我的朋友发出HTTP帖子请求';的网站


Simple PHP script to make an HTTP post request to my friend's website

我是网络编程的新手,正在尝试制作一个简单的PHP脚本来向我朋友的网站发送URL请求(最终我希望能够发送垃圾邮件,因为他有评论区哈哈)。我试着从这里复制一个脚本http://www.php.net/manual/en/httprequest.send.php并根据自己的用途对其进行了修改,但我不知道出了什么问题。

这是我的:

<!DOCTYPE html>
<html>
<head>
<title>attack test</title>
</head>
<body>
<?php
$r = new HttpRequest('http://sitename.us', HttpRequest::METH_POST);
try {
    $r->send();
    echo $r->getResponseCode();
} catch (HttpException $ex) {
    echo $ex;
}
?>
</body>
</html>

以下是我对它应该做什么的理解:

为URL http://feucht.us和请求类型METH_POST创建一个HttpRequest变量的实例。

尝试发送请求并打印响应代码。如果有HttpException类型的异常,请打印它。

无论哪种方式,都应该打印一些内容,但当我运行脚本时,不会打印任何内容。

有什么帮助吗?

从这里开始

<?php
//
// A very simple PHP example that sends a HTTP POST to a remote site
//
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.mysite.com/tester.phtml");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "postvar1=value1&postvar2=value2&postvar3=value3");
// in real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS, 
//          http_build_query(array('postvar1' => 'value1')));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch)