clox / hicurl
hicurl是PHP cURL扩展的一个面向对象的封装器。然而,其主要功能是能够保存请求的页面,并且还包含一个用于查看保存数据的javascript "类"。
- dev-master
- v3.14.0
- v3.13.0
- v3.12.0
- v3.11.0
- v3.10.0
- v3.9.1
- v3.9.0
- v3.8.0
- v3.7.0
- v3.6.0
- v3.5.0
- v3.4.0
- v3.3.0
- v3.1.0
- v3.0.0
- 2.x-dev
- v2.0.3-a
- v2.0.2-a
- v2.0.1
- v2.0.1-a
- v2.0.0-a
- v1.6.0
- v1.5.0
- 1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- dev-prepare_for_v2
- dev-complete_separating_customData_and_also_remove_static_methods
- dev-separate_customData_from_compile()
- dev-Store_history_as_separate_files
This package is auto-updated.
Last update: 2024-09-15 23:27:12 UTC
README
这是一个旨在使cURL请求变得简单,同时允许将获取的页面以及头部信息和postdata保存到文件中以便以后查看的库。本质上是一个cURL的PHP包装类和一个用于以美观方式显示保存数据的javascript "类"。
入门
### 简单用法 要在PHP中使用Hicurl,您只需在src文件夹中包含hicurl.php
require_once 'hicurl/src/hicurl.php';
然后您可以进行如下操作以开始加载一些页面
$hicurl=new Hicurl(); $google=$hicurl->loadSingle('www.google.com'); The $google-variable will now hold an associative array looking like: [ 'content'=>page-content ,'headers'=>all the received headers ,'error'=>false for success, otherwise a description of the error ]
发送post-data也很简单。如果将对象传递给第二个参数,则请求将以POST方式发送该数据
require_once 'hicurl/src/hicurl.php'; $hicurl=new Hicurl(); $hicurl->loadSingle('http://www.htmlcodetutorial.com/cgi-bin/mycgi.pl',['foo'=>'bar']);
### 设置
有一系列可以使用的设置。这些设置可以传递或像这样
$hicurl=new Hicurl(['cookie'=>'cookies/cookie.txt']);
使用该实例发出的任何调用现在将保存和发送该文件中的cookies。设置可以在实例创建后更改
$hicurl->settings(['cookie'=>'cookies/muffin.txt']);
最后,它们还可以传递给load调用,在这种情况下,它们将仅在该调用期间与实例的设置合并
$hicurl->loadSingle('www.google.com',null,['cookie'=>'cookies/macarone.txt']);
### 静态使用 大多数方法也有静态对应物,如果只需要进行单个调用,则这很方便
$result=Hicurl->loadSingleStatic($url,$postData,['cookie'=>'cake.txt']);
在不使用hicurl的情况下,这可能类似于以下内容
$ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_POST, true); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); curl_setopt($ch,CURLINFO_HEADER_OUT,true); curl_setopt($ch,CURLOPT_COOKIEFILE],'cake.txt'); curl_setopt($ch,CURLOPT_COOKIEJAR]'cake.txt'); $postDataString=""; foreach ($postData as $key=>$value) { $postDataString.=urlencode($key)."=".urlencode($value)."&"; } curl_setopt($ch,CURLOPT_POSTFIELDS, trim($string, ",")); $result=['content'=>curl_exec($ch),'headers'=>curl_getinfo($ch)]; curl_close($ch);
"哇!"### 保存历史记录 保存数据也很简单。首先,我们需要一个额外的设置
//set a history output filepath. This setting will be used for subsequent load-calls and will make them save data to that file. $hicurl->settings(['history'=>'history/myHistoryFile']); //load a couple pages. they will be saved to myHistoryFile $hicurl->loadSingle("www.google.com"); $hicurl->loadSingle("www.facebook.com"); //When we are done writing to the file we need to "compile it". //This puts it in a closed state, and also compresses it. //This is the state it is sent to the client in. $hicurl->compileHistory();
### 发送历史记录 有一些简单的工作要做,以便将数据发送到客户端。以下是一种方法
getHistory.php
require_once 'hicurl/src/hicurl.php'; Hicurl::serveHistory('history/myHistoryFile');
这就是我们需要发送数据的内容。虽然简单地通过浏览器加载此页面帮助不大,因此我们需要做以下操作...### 查看历史记录 要以有意义的方式查看数据,我们将使用javascript hicurl-class。我们需要加载一些文件来使用它,然后编写一些额外的代码。
<!--This is the js "class" used for viewing the history--> <script src="hicurl/src/hicurl.js"></script> <!--...it needs this css-file to display things correctly--> <link rel="stylesheet" type="text/css" href="hicurl/src/hicurl.css"> <!--It also required jQuery--> <script src="hicurl/src/libs/jquery-1.11.2.min.js"></script> <!--.And jquery easy UI--> <script src="hicurl/src/libs/jquery.easyui.min.js"></script> <!--...along with it's css-file--> <link rel="stylesheet" type="text/css" href="../../src/libs/easyui.css"> <!--This can optionally be included and will make html-code display better--> <script src="hicurl/src/libs/beautify-html.js"></script> <!--Now for initiating the class--> <script> //it expects a DOM-element in its first parameter, where everything will be rendered unto. //As second parameter we will need to pass a url-string where it will fetch the history-data from. hicurl=new Hicurl(document.body,"getMyHistory.php"); //We will need to create that page, e.g. "getHistory.php" in this case, and make it send the data. </script>