}
$pageContents = $client->getContent();
带自动转向的Get方法
PHP代码
$client = new HttpClient(''www.amazon.com'');
$client->setDebug(true);
if (!$client->get(''/'')) {
die(''An error occurred: ''.$client->getError());
}
$pageContents = $client->getContent();
检查页面是否存在
PHP代码
$client = new HttpClient(''example.com'');
$client->setDebug(true);
if (!$client->get(''/thispagedoesnotexist'')) {
die(''An error occurred: ''.$client->getError());
}
if ($client->getStatus() == ''404'') {
echo ''Page does not exist!'';
}
$pageContents = $client->getContent();
伪造客户端
PHP代码
$client = new HttpClient(''example.com'');
$client->setDebug(true);
$client->setUserAgent(''Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3a) Gecko/20021207'');
if (!$client->get(''/'')) {
die(''An error occurred: ''.$client->getError());
}
$pageContents = $client->getContent();
登录验证并请求一个网页
PHP代码
$client = new HttpClient(''example.com'');
$client->post(''/login.php'', array(
''username'' => ''Simon'',
''password'' => ''ducks''
));
if (!$client->get(''/private.php'')) {
die(''An error occurred: ''.$client->getError());
}
$pageContents = $client->getContent();
HTTP授权
PHP代码
$client = new HttpClient(''example.com'');
$client->setAuthorization(''Username'', ''Password'');
if (!$client->get(''/'')) {
  |