-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.php
61 lines (49 loc) · 1.45 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
require './src/Curl.php';
require './src/CurlException.php';
require './src/CurlResponse.php';
use SujeetKV\CurlLib\Curl;
$curl = new Curl(array(
'timeout' => 30, // time limit for request
'strict_mode' => false, // whether CURLOPT_FAILONERROR or not
'max_redirects' => 10, // number of redirections to follow
'http_version' => '1.1' // HTTP version (1.1, 1.0)
));
// simple GET request
$res1 = $curl->get('http://example.com');
//echo $res1;
echo '<pre>';
echo $res1->getProtocolVersion() . PHP_EOL;
echo $res1->getStatusCode() . ' ' . $res1->getReasonPhrase() . PHP_EOL;
print_r($res1->getHeaders());
print_r($curl->getInfo());
echo '</pre>';
// simple POST request
$res2 = $curl->post('http://example.com', array('name' => 'Sujeet', 'age' => 25), array(CURLOPT_TIMEOUT => 20));
//echo $res2;
echo '<pre>';
print_r($curl->getInfo());
echo '</pre>';
// custom request
$res3 = $curl->sendRequest('GET', 'http://example.com');
//echo $res3;
echo '<pre>';
print_r($curl->getInfo());
echo '</pre>';
// custom request
$res4 = $curl->setOptions(array(
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => array('name' => 'Sujeet', 'age' => 25),
CURLOPT_TIMEOUT => 25
))->execute('http://example.com');
//echo $res4;
echo '<pre>';
print_r($curl->getInfo());
echo '</pre>';
// simple HEAD request
$res5 = $curl->head('http://example.com');
echo '<pre>';
print_r($res5->getHeaders());
echo '</pre>';