92 $this->method = strtoupper(
$method);
94 $this->request = http_build_query(
$params);
99 $this->requestHeaders = explode(
"\n",
$header);
114 if (function_exists(
'curl_init')) {
120 curl_setopt($ch, CURLOPT_URL, $this->url);
121 if (!empty($this->requestHeaders)) {
122 curl_setopt($ch, CURLOPT_HTTPHEADER, $this->requestHeaders);
124 curl_setopt($ch, CURLOPT_HEADER, 0);
126 if ($this->method ===
'POST') {
127 curl_setopt($ch, CURLOPT_POST,
true);
128 curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request);
129 }
else if ($this->method !==
'GET') {
130 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method);
131 if (!is_null($this->request)) {
132 curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request);
135 curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true);
136 curl_setopt($ch, CURLINFO_HEADER_OUT,
true);
137 curl_setopt($ch, CURLOPT_HEADER,
true);
139 #curl_setopt($ch, CURLOPT_SSLVERSION,3); 140 $chResp = curl_exec($ch);
145 $this->ok = $chResp !==
false;
147 $chResp = str_replace(
"\r\n",
"\n", $chResp);
148 $chRespSplit = explode(
"\n\n", $chResp, 2);
149 if ((count($chRespSplit) > 1) && (substr($chRespSplit[1], 0, 5) ===
'HTTP/')) {
150 $chRespSplit = explode(
"\n\n", $chRespSplit[1], 2);
152 $this->responseHeaders = $chRespSplit[0];
153 $resp = $chRespSplit[1];
154 $this->status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
155 $this->ok = $this->status < 400;
157 $this->error = curl_error($ch);
160 $this->requestHeaders = str_replace(
"\r\n",
"\n", curl_getinfo($ch, CURLINFO_HEADER_OUT));
162 $this->response = $resp;
165 $opts = array(
'method' => $this->method,
166 'content' => $this->request
168 if (!empty($this->requestHeaders)) {
172 $ctx = stream_context_create(array(
'http' => $opts));
173 $fp = @
fopen($this->url,
'rb',
false, $ctx);
175 $resp = @stream_get_contents($fp);
176 $this->ok = $resp !==
false;
$ok
True if message was sent successfully.
__construct($url, $method='GET', $params=null, $header=null)
Class constructor.
$status
Status of response (0 if undetermined).
send()
Send the request to the target URL.
$requestHeaders
Request headers.
$responseHeaders
Response headers.
static getLogger($a_component_id)
Get component logger.
Class to represent an HTTP message.