PHP code example of datingvip / curl

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

    

datingvip / curl example snippets




use DatingVIP\cURL\Request;
use DatingVIP\cURL\Response;

try {
	$response = (new Request())
		->setHeadersUsed(true)
		->get("http://www.example.com");
} catch (\RuntimeException $ex) {
	echo (string) $ex;
} finally {
	printf("Got %d bytes from %s in %.3f seconds\n",
		strlen((string)$response),
		$response->getURL(),
		$response->getTime());
}



use DatingVIP\cURL\Request;
use DatingVIP\cURL\Response;

try {
	$response = (new Request())
		->setHeadersUsed(true)
		->post("http://www.example.com", ["hello" => "world"]);
} catch (\RuntimeException $ex) {
	echo (string) $ex;
} finally {
	printf("Posted %d bytes from %s in %.3f seconds\n",
		strlen((string)$response),
		$response->getURL(),
		$response->getTime());
}



use DatingVIP\cURL\Request;
use DatingVIP\cURL\Response;

try {
	$request = new Request([
		CURLOPT_HTTPHEADER => [
			"x-my-header" => "x-my-value"
		],
		CURLOPT_URL => "http://www.example.com"
	]);

	$response = new Response($request);
} catch (\RuntimeException $ex) {
	echo (string) $ex;
} finally {
	if ($response instanceof Response) {
		printf("Got %d bytes from %s in %.3f seconds\n",
			strlen((string)$response),
			$response->getURL(),
			$response->getTime());
	}
}