偶改的一个类,原来只支持GET (http/https)<?php $data = "login=" . urlencode("abc") . "&password=" . urlencode("123456")."&checkpass=".urlencode("Login!"); $r=new HTTPRequest("https://localhost/csdn/pass.php","POST",$data); /** * * 支持GET | POST * HTTP | HTTPS */ class HTTPRequest { var $mArray=array("GET","POST"); var $_fp; // HTTP socket var $_url; // full URL var $_host; // HTTP host var $_protocol; // protocol (HTTP/HTTPS) var $_uri; // request URI var $_method; // method var $_query; // query var $_port; // port
// scan url function _scan_url() { $req = $this->_url;
Q: Why can't I fetch https pages? A: Using Snoopy to fetch an https page requires curl. Check if curl is installed on your host. If curl is installed, it may be located in a different place than the default. By default Snoopy looks for curl in /usr/local/bin/curl. Run 'which curl' and find out your location. If it differs from the default, then you'll need to set the $snoopy->curl_path variable to the location of your curl installation. Here's an example of the code : include "Snoopy.class.php"; $snoopy = new Snoopy; $snoopy->curl_path="/usr/bin/curl";这个是snoopy类得支持https得文档,,不懂啥子意思。。类里面要用到$snoopy->curl_path是否可以执行,,如果是文件名肯定不可以执行撒
这个类可以mail给我么??[email protected]谢谢老……
php的curl看了些,,没有实践的经验,,写不出来……
修改php.ini
extension = open_ssl.dll修改httpClient类
1处 => 构造函数 修改如下:
function HttpClient($host, $port=80, $ssl=false) {
$this->host = $host;
$this->port = $port;
$this->ssl = $ssl;
}2处 => doRequest函数 修改如下
function doRequest(){
$host = $this->ssl ? "ssl://" . $this->host : $this->host; <= 增加此行在调用类的时候,如果使用https要指定端口,一般为443
$http = new HttpClient( "www.test.com", 443, true );
什么类这么厉害能识别出验证码?
=-------------
不需要识别,但是需要把验证码也显示出来手动填写:)
---------------------
谢谢ice_berg16(寻梦的稻草人),我再看看程序:)
$data = "login=" . urlencode("abc") . "&password=" . urlencode("123456")."&checkpass=".urlencode("Login!");
$r=new HTTPRequest("https://localhost/csdn/pass.php","POST",$data);
/**
*
* 支持GET | POST
* HTTP | HTTPS
*/
class HTTPRequest
{
var $mArray=array("GET","POST");
var $_fp; // HTTP socket
var $_url; // full URL
var $_host; // HTTP host
var $_protocol; // protocol (HTTP/HTTPS)
var $_uri; // request URI
var $_method; // method
var $_query; // query
var $_port; // port
// scan url
function _scan_url()
{
$req = $this->_url;
$pos = strpos($req, '://');
$this->_protocol = strtolower(substr($req, 0, $pos));
$req = substr($req, $pos+3);
$pos = strpos($req, '/');
if($pos === false)
$pos = strlen($req);
$host = substr($req, 0, $pos);
if(strpos($host, ':') !== false)
{
list($this->_host, $this->_port) = explode(':', $host);
}
else
{
$this->_host = $host;
$this->_port = ($this->_protocol == 'https') ? 443 : 80;
}
$this->_uri = substr($req, $pos);
if($this->_uri == '')
$this->_uri = '/';
}
// constructor
function HTTPRequest($url,$method="GET",$query="")
{
$this->_method=(in_array($method,$this->mArray))?$method:"GET";
$this->_url = $url;
$this->_query = $query;
$this->_scan_url();
}
// download URL to string
function DownloadToString()
{
$crlf = "\r\n";
// generate request
$req = $this->_method ." ". $this->_uri . ' HTTP/1.0' . $crlf
. 'Host: ' . $this->_host . $crlf.(($this->_method=="POST")?("Content-type: application/x-www-form-urlencoded\r\nUser-Agent: Mozilla 4.0\r\nContent-length: ".strlen($this->_query)."\r\nAccept: */*\r\n\r\n$this->_query".$crlf.$crlf):$crlf);
// fetch
$this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port, $errno, $errstr, 30);
fwrite($this->_fp, $req);
while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
$response .= fread($this->_fp, 1024);
fclose($this->_fp);
// split header and body
$pos = strpos($response, $crlf . $crlf);
if($pos === false)
return($response);
$header = substr($response, 0, $pos);
$body = substr($response, $pos + 2 * strlen($crlf));
// parse headers
$headers = array();
$lines = explode($crlf, $header);
foreach($lines as $line)
if(($pos = strpos($line, ':')) !== false)
$headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
// redirection?
if(isset($headers['location']))
{
$http = new HTTPRequest($headers['location']);
return($http->DownloadToString($http));
}
else
{
return($body);
}
}
}
?>
A: Using Snoopy to fetch an https page requires curl. Check if curl is installed on your host. If curl is installed, it may be located in a different place than the default. By default Snoopy looks for curl in /usr/local/bin/curl. Run 'which curl' and find out your location. If it differs from the default, then you'll need to set the $snoopy->curl_path variable to the location of your curl installation. Here's an example of the code :
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->curl_path="/usr/bin/curl";这个是snoopy类得支持https得文档,,不懂啥子意思。。类里面要用到$snoopy->curl_path是否可以执行,,如果是文件名肯定不可以执行撒
我用这个修改的类取https的内容都没有问题。
但是好像还是没有搞定
我用这个修改的类取https的内容都没有问题。
------------
嘿嘿,,你修改那儿确实有问题。。
应该是:$this->host = $this->ssl ? "ssl://" . $this->host : $this->host;
而不是$host = $this->ssl ? "ssl://" . $this->host : $this->host;httpclient类依着顺序调试老一下,眼睛都看花了现在好了,谢谢哈:) scsjs(闪电回归) ( ) 信誉:100 2006-05-22 09:29:00 得分: 0
:) 二個稻草人 ,,,,, :)
------------
他寻梦,我已经寻到了。。;)
=>
if (!$fp = @fsockopen($host, $this->port, $errno, $errstr, $this->timeout)) {不过你改成那样下面就不用改了,一样的
------------
他寻梦,我已经寻到了。。;)
------------------------------
樓主真的找到了呀!!告訴我,在哪裏的說,偶也想要一個...