谁能给我一个HttpRequest类的源码? RT 谢谢!官方的或者DIY的都行 如果是自己写的 麻烦给个使用方法举例 谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?phpclass HttpRequest{var $sHostAdd;var $sUri;var $iPort;var $sRequestHeader;var $sResponse;function HttpRequest($sUrl){$sPatternUrlPart = '/http:\/\/([a-z-\.0-9]+)(:(\d+)){0,1}(.*)/i';$arMatchUrlPart = array();preg_match($sPatternUrlPart, $sUrl, $arMatchUrlPart);$this->sHostAdd = gethostbyname($arMatchUrlPart[1]);if (empty($arMatchUrlPart[4])){$this->sUri = '/';}else{$this->sUri = $arMatchUrlPart[4];}if (empty($arMatchUrlPart[3])){$this->iPort = 80;}else{$this->iPort = $arMatchUrlPart[3];}$this->addRequestHeader('Host: '.$arMatchUrlPart[1]);$this->addRequestHeader('Connection: Close');}function addRequestHeader($sHeader){$this->sRequestHeader .= trim($sHeader)."\r\n";}function sendRequest($sMethod = 'GET', $sPostData = ''){$sRequest = $sMethod." ".$this->sUri." HTTP/1.1\r\n";$sRequest .= $this->sRequestHeader;if ($sMethod == 'POST'){$sRequest .= "Content-Type: application/x-www-form-urlencoded\r\n";$sRequest .= "Content-Length: ".strlen($sPostData)."\r\n";$sRequest .= "\r\n";$sRequest .= $sPostData."\r\n";}$sRequest .= "\r\n";$sockHttp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);if (!$sockHttp){die('socket_create() failed!');}$resSockHttp = socket_connect($sockHttp, $this->sHostAdd, $this->iPort);if (!$resSockHttp){die('socket_connect() failed!');}socket_write($sockHttp, $sRequest, strlen($sRequest));$this->sResponse = '';while ($sRead = socket_read($sockHttp, 4096)){$this->sResponse .= $sRead;}socket_close($sockHttp);}function getResponse(){return $this->sResponse;}function getResponseBody(){$sPatternSeperate = '/\r\n\r\n/';$arMatchResponsePart = preg_split($sPatternSeperate, $this->sResponse, 2);return $arMatchResponsePart[1];}function getResponseHead(){$sPatternSeperate = '/\r\n\r\n/';$arMatchResponsePart = preg_split($sPatternSeperate, $this->sResponse, 2);return $arMatchResponsePart[0];}}/***调用方法*/$httpre=new HttpRequest("http://127.0.0.1/testclient.php");$httpre->sendRequest();$re=$httpre->getResponseBody();print_r($httpre->getResponseHead());print_r($re);?> 呃... 怎样开启socket模块是在php.ini里面把;extension=php_sockets.dll前面的分号去掉吗? 去掉之后,在phpinfo();里看看有没打开 这个类支持https的请求吗? 多用户博客,用什么开源程序做二次开发比较好? magento中xml文件问题 thinkphp部分页面为空白 QQ空间上的信息同步到DiscuzX2.5有没有什么方法 UCHOME 插件外包 mysql 条件 PHP 高手或解密高手请进 急急急!!! 织梦程序调取另外一个数据库信息 使用sae定时任务实现终身自动发表微博(PHP实现) discuz这段代码如何理解 关于PHP分页 mysql 4 开启严格模式?
<?php
class HttpRequest{
var $sHostAdd;
var $sUri;
var $iPort;var $sRequestHeader;var $sResponse;function HttpRequest($sUrl)
{$sPatternUrlPart = '/http:\/\/([a-z-\.0-9]+)(:(\d+)){0,1}(.*)/i';
$arMatchUrlPart = array();
preg_match($sPatternUrlPart, $sUrl, $arMatchUrlPart);$this->sHostAdd = gethostbyname($arMatchUrlPart[1]);
if (empty($arMatchUrlPart[4]))
{
$this->sUri = '/';
}
else
{
$this->sUri = $arMatchUrlPart[4];
}
if (empty($arMatchUrlPart[3]))
{
$this->iPort = 80;
}
else
{
$this->iPort = $arMatchUrlPart[3];
}$this->addRequestHeader('Host: '.$arMatchUrlPart[1]);
$this->addRequestHeader('Connection: Close');}function addRequestHeader($sHeader)
{
$this->sRequestHeader .= trim($sHeader)."\r\n";
}function sendRequest($sMethod = 'GET', $sPostData = '')
{
$sRequest = $sMethod." ".$this->sUri." HTTP/1.1\r\n";
$sRequest .= $this->sRequestHeader;
if ($sMethod == 'POST')
{
$sRequest .= "Content-Type: application/x-www-form-urlencoded\r\n";
$sRequest .= "Content-Length: ".strlen($sPostData)."\r\n";
$sRequest .= "\r\n";
$sRequest .= $sPostData."\r\n";
}
$sRequest .= "\r\n";$sockHttp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!$sockHttp)
{
die('socket_create() failed!');
}$resSockHttp = socket_connect($sockHttp, $this->sHostAdd, $this->iPort);
if (!$resSockHttp)
{
die('socket_connect() failed!');
}socket_write($sockHttp, $sRequest, strlen($sRequest));$this->sResponse = '';
while ($sRead = socket_read($sockHttp, 4096))
{
$this->sResponse .= $sRead;
}socket_close($sockHttp);
}function getResponse()
{
return $this->sResponse;
}function getResponseBody()
{
$sPatternSeperate = '/\r\n\r\n/';
$arMatchResponsePart = preg_split($sPatternSeperate, $this->sResponse, 2);
return $arMatchResponsePart[1];
}function getResponseHead()
{
$sPatternSeperate = '/\r\n\r\n/';
$arMatchResponsePart = preg_split($sPatternSeperate, $this->sResponse, 2);
return $arMatchResponsePart[0];
}
}/**
*调用方法
*/
$httpre=new HttpRequest("http://127.0.0.1/testclient.php");
$httpre->sendRequest();
$re=$httpre->getResponseBody();
print_r($httpre->getResponseHead());
print_r($re);
?>
呃... 怎样开启socket模块
是在php.ini里面把;extension=php_sockets.dll前面的分号去掉吗?
去掉之后,在phpinfo();里看看有没打开
这个类支持https的请求吗?