eays
(eays)
注册会员

中级会员
UID 65358
精华
0
积分 190
帖子 174
金钱 190 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2005-8-1 来自 四川.中国
状态 离线
|
[广告]: 代充Paypal帐号美元
Socket连接第二次发送请求时获得的还是第一次的数据????
我的Socket类:
<?php class Socket_Client{ var $SocketClient; var $Host; var $Port; var $TimeOut; var $ErrNo; var $ErrStr; var $SendContent = ''; var $GetContent; var $HttpPost; var $HttpGet;
function Connect($Host , $Port = 80 , $TimeOut = 30 ){ $this->Port = $Port; $this->TimeOut = $TimeOut; $this->Host = $Host; return $this->SocketClient = fsockopen(gethostbyname($this->Host),$this->Port,$this->ErrNo,$this->ErrStr,$this->TimeOut) or exit($this->ErrStr."--->".$this->ErrNo); }
function SendPost($Posto,$PostFrom,$ContentArray){ if(!$this->SocketClient) return 'Socket Client Not Opened.';
$flag = 0; foreach ($ContentArray as $key=>$value) { if ($flag!=0) { $this->SendContent .= "&"; $flag = 0; } $this->SendContent.= $key."="; $this->SendContent.= urlencode($value); $flag = 1; }
$this->HttpPost = "POST ".$Posto." HTTP/1.1rn"; $this->HttpPost .= "Host:".gethostbyname($this->Host)."rn"; $this->HttpPost .= "Referer:".$PostFrom."rn"; $this->HttpPost .= "Content-Type: application/x-www-form-urlencodedrn"; $this->HttpPost .= "Content-Length: ".strlen($this->SendContent)."rn"; $this->HttpPost .= "Connection: Closernrn"; $this->HttpPost .= $this->SendContent."rn"; return fputs($this->SocketClient,$this->HttpPost); }
function SendGet($Geto,$GetForm){ $this->HttpGet = "GET ".$Geto." HTTP/1.1rn"; $this->HttpGet .= "Host: ".gethostbyname($this->Host)."rn"; $this->HttpGet .= "Accept: */*rn"; $this->HttpGet .= "Referer: ".$GetForm."rn"; $this->HttpGet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)rn"; $this->HttpGet .= "Connection: Closernrn"; return fputs($this->SocketClient,$this->HttpGet); }
function Get(){ if(!$this->SocketClient) return 'Socket Client Not Opened.'; while (!feof($this->SocketClient)) { $this->GetContent .= fgets($this->SocketClient,1024); } return $this->GetContent; }
function Close(){ fclose($this->SocketClient); }
} ?> 使用类:
$Socket = new Socket_Client();
$Socket->SendPost("/cgi-bin/nEWpAYcENTER/Domain/DomainLogin","/domainmanage/management.htm",$ContentArray);
echo $Socket->Get(); #这里返回的是第一次请求POST返回的内容.
$Socket->SendGet($GetHttpURL,"/cgi-bin/nEWpAYcENTER/Domain/DomainLogin");
echo $Socket->Get(); #这里应该是请求GET时的内容,但还是第一次POST的内容.
如果建两个Socket连接则不会有这问题.请问有没有办法用一个Socket连接搞定~~~
|
|