PHP code example of kajna / curli

1. Go to this page and download the library: Download kajna/curli 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/ */

    

kajna / curli example snippets


try {
	$curli = (new \Curli\Curli())
			->get('http://example.com')
			->close();

	$response = $curli->response();

	echo $response->asText();
} catch(\Exception $e) {
	echo $e->getMessage();
}

try {
	$data = array('foo' => 'bar');
	$json = json_encode($data);

	$curli = (new \Curli\Curli())
			->setConnectionTimeout(3)
			->setHeader('Content-Type', 'application/json')
			->setHeader('Content-Length', strlen($json))
			->setParams($json)
			->put('http://example.com')
			->close();

	$response = $curli->response();

	print_r($response->asObject());
} catch(\Exception $e) {
	echo $e->getMessage();
}

try {
	$data = '<root><foo>bar</foo></root>';

	$curli = (new \Curli\Curli())
			->setUserAgent('curl 7.16.1 (i386-portbld-freebsd6.2) libcurl/7.16.1 OpenSSL/0.9.7m zlib/1.2.3')
			->setHeader('Content-Type', 'text/xml')
			->setHeader('Content-Length', strlen($data))
			->setParams($data)
			->post('http://example.com')
			->close();

	$response = $curli->response();

	print_r($response->asArray());
} catch(\Exception $e) {
	echo $e->getMessage();
}