PHP code example of proclnas / curl-rox
1. Go to this page and download the library: Download proclnas/curl-rox library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
proclnas / curl-rox example snippets
use CurlRox\Curl;
try {
$curl = new Curl;
$curl->setUri('http://httpbin.org/get');
$curl->getRequest();
$r = $curl->getHttpResponse();
echo $r;
} catch (Exception $e) {
echo $e->getMessage();
}
try {
$curl = new Curl;
$curl->setUri('http://httpbin.org/post');
$curl->setPostPayload(['name' => 'Proclnas', 'Language' => 'PHP'])
$curl->postRequest();
$r = $curl->getHttpResponse();
echo $r;
} catch (Exception $e) {
echo $e->getMessage();
}
try {
$curl = new Curl;
$curl->setUri('http://httpbin.org/get');
$curl->setHttpHeaders([
'X-Requested-With' => 'XMLHttpRequest'
]);
$curl->getRequest();
$r = $curl->getHttpResponse(true);
var_dump($r);
} catch (Exception $e) {
echo $e->getMessage();
}
try {
$curl = new Curl;
$curl->setUri('http://google.com');
$curl->getRequest();
$curl->setCallback(function($httpResponse, \DiDom\Document $dom, Curl $curlRox){
$elements = $dom->find('a');
foreach ($elements as $element)
echo 'Link found: ', $element->attr('href'), PHP_EOL;
});
} catch (Exception $e) {
echo $e->getMessage();
}
try {
$curl = new Curl;
$curl->setUri('http://fake-links.org/');
$curl->getRequest();
$curl->setCallback(function($http_response, \DiDom\Document $dom, Curl $curlRox){
// Check http code
if (!$curlRox->ok())
exit (
sprintf('Error reaching %s, http_code: %s' . PHP_EOL, $curlRox->getUri(), $curlRox->getHttpInfo('http_code'))
);
$elements = $dom->find('a');
foreach ($elements as $element)
echo 'Link found: ', $element->attr('href'), PHP_EOL;
});
} catch (Exception $e) {
echo $e->getMessage();
}
try {
$curl = new Curl;
$curl->setUri('http://fake-links.org/');
$curl->getRequest();
$curl->debugTo('/tmp/review.html');
} catch (Exception $e) {
echo $e->getMessage();
}
Curl::__construct($uri = null)
Curl::__destruct()
Curl::setUri($uri)
Curl::getUri()
Curl::setCookieFile($cookie_file);
Curl::getCookieFile()
Curl::setUserAgent($user_agent)
Curl::getUserAgent()
Curl::setRaw($raw = true)
Curl::getRaw()
Curl::setFollowLocation($follow_location)
Curl::getFollowLocation()
Curl::setTimeout($timeout)
Curl::getTimeout()
Curl::encoding($encoding)
Curl::getEncoding()
Curl::setHttpHeaders($http_headers)
Curl::getHttpHeaders()
Curl::setAutoReferer($bool)
Curl::getAutoReferer()
Curl::checkSsl($bool)
Curl::getCaCert()
Curl::getCheckSsl()
Curl::setPostPayload($post_payload)
Curl::getPostPayload()
Curl::getRequest()
Curl::postRequest()
Curl::getHttpInfo($http_info_key)
Curl::getHttpResponse($bool_json_decode)
Curl::ok()
Curl::getLastHttpCode()
Curl::setCallback($callable)
Curl::debugTo($file)