HTTP CURL

' HTTP CURL.

1
stream_context_create

,

1
fopen

1
stream_get_contents

:

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75 76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class Custom_Http_Request
{
private $ _url;
private $ _body;
private $ _method = 'POST';
private $ _headers = array (); private $ _response;
private $ _stream;

public function __construct ($ url, $ body)
{
if (empty ($ url) | | empty ($ body)) {
throw new Exception ('Both URL and BODY are required'
. 'For fetching the request .'); }

$ This->_url = $ url;
$ This->_body = $ body;
}

public function setMethod ($ method)
{
if ('POST' == $ method | | 'GET' == $ method) {
$ This->_method = $ method;
return $ this;
}

throw new Exception ('Invalid method set .'); }

public function addHeader (array $ header)
{
if (! empty ($ header)) {
$ This->_headers [] = $ header;
return $ this;
}

throw new Exception ('The headers are empty .'); }

public function getMethod ()
{
return $ this->_method;
}

public function getBody ()
{
return $ this->_body;
}

public function getHeaders ()
{
return $ this->_headers;
}

public function getResponse ()
{
if (is_null ($ this->_stream)) {
$ This->_openStream ();
}

if (is_null ($ this->_response)) {
$ This->_response = @ stream_get_contents ($ this->_stream);

if (false === $ this->_response) {
throw new Exception ('It is not possible to'
. 'Read from the response .'); }
}

return $ this->_response;
}

private function _assemble ()
{
$ Params = array (
'Http' =>array (
'Method' =>$ this->_method,
'Content' =>$ this->_body
)
);

if (! empty ($ this->_headers)) {
$ Params ['http'] ['header'] = $ this->_headers;
}

return stream_context_create ($ params);
}

private function _openStream ()
{
$ This->_stream = @ fopen ($ this->_url, 'rb', false, $ this->_assemble ());
if (! $ this->_stream) {
throw new Exception ('It was not possible to'
. "Connect to {$ this->_url }."); }
}
}

, cURL.

: 28/03/11 @ 01:33

:

.
SEO Toolbar Chrome SEOmoz
̳ description (keywords) html-
GOODAR.com ! :)
25%