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)." ";
}
function sendRequest($sMethod = 'GET', $sPostData = ''){
$sRequest = $sMethod." ".$this->sUri." HTTP/1.1 ";
$sRequest .= $this->sRequestHeader;
if ($sMethod == 'POST'){
$sRequest .= "Content-Type: application/x-www-form-urlencoded ";
$sRequest .= "Content-Length: ".strlen($sPostData)." ";
$sRequest .= " ";
$sRequest .= $sPostData." ";
}
$sRequest .= " ";
$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));
Magento是一套专业开源的PHP电子商务系统。Magento设计得非常灵活,具有模块化架构体系和丰富的功能。易于与第三方应用系统无缝集成。Magento开源网店系统的特点主要分以下几大类,网站管理促销和工具国际化支持SEO搜索引擎优化结账方式运输快递支付方式客户服务用户帐户目录管理目录浏览产品展示分析和报表Magento 1.6 主要包含以下新特性:•持久性购物 - 为不同的
0
$this->sResponse = '';
while ($sRead = socket_read($sockHttp, 4096)){
$this->sResponse .= $sRead;
}
socket_close($sockHttp);
}
function getResponse(){
return $this->sResponse;
}
function getResponseBody(){
$sPatternSeperate = '/ /';
$arMatchResponsePart = preg_split($sPatternSeperate, $this->sResponse, 2);
return $arMatchResponsePart[1];
}
function getResponseHead(){
$sPatternSeperate = '/ /';
$arMatchResponsePart = preg_split($sPatternSeperate, $this->sResponse, 2);
return $arMatchResponsePart[0];
}
}
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号