PHP code example of oksuz / curl
1. Go to this page and download the library: Download oksuz/curl 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/ */
oksuz / curl example snippets
$cli = new \Oksuz\Curl\Request("http://example.org");
/** @var \Oksuz\Curl\Response $result */
$result = $cli->result();
//echo $result->getHeader();
//echo $result->getStatusCode();
echo $result->getResponse();
$cli = new \Oksuz\Curl\Request("http://example.org")
/** @var \Oksuz\Curl\Response $result */
$result = $cli->post(array("username" => "foo", "password" => "bar"))
->addReferer("http://www.google.com/?q=example")
->setOpt(CURLOPT_USERAGENT, "firefox/2.0.16") // you can add php's CURL_CONSTANTS
->result();
$clients = array();
$clients[] = new \Oksuz\Curl\Request("http://example1.org");
$clients[] = new \Oksuz\Curl\Request("http://example2.org");
$clients[] = new \Oksuz\Curl\Request("http://example3.org");
$runner = new \Oksuz\Curl\Runner();
/** @var Array $result contains \Oksuz\Curl\Response */
$result = $runner->runMultiple($cli);
$curl = new \Oksuz\Curl\Request();
$response = $curl->url("http://www.example.org/login")
->post(array("username" => "user", "password" => "password"))
->addCookieSupport()
//OR ->addCookieSupport("/path/to/cookiejar_cookiefile.txt")
->result();
if (200 == $response->getStatusCode()) {
$resp = $curl->url("http://www.example.com/private_area")
->get(array("page" => 1, "do" => "show")) // http://www.example.com/private_area?page=1&do=show
->addHeader(array("HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"))
->addCookie(array("cookie_name" => "cookie_value"))
->setBasicAuth("username", "password")
->result();
var_dump($resp);
}
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_USERAGENT => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36",
CURLOPT_HEADER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,