28 curl_setopt($ch, CURLOPT_URL, $message->
getUrl());
29 if (!empty($message->requestHeaders)) {
30 curl_setopt($ch, CURLOPT_HTTPHEADER, $message->requestHeaders);
32 curl_setopt($ch, CURLOPT_HEADER, 0);
35 curl_setopt($ch, CURLOPT_POST,
true);
36 curl_setopt($ch, CURLOPT_POSTFIELDS, $message->request);
37 } elseif ($message->
getMethod() !==
'GET') {
38 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $message->
getMethod());
39 if (!is_null($message->request)) {
40 curl_setopt($ch, CURLOPT_POSTFIELDS, $message->request);
43 curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true);
44 curl_setopt($ch, CURLINFO_HEADER_OUT,
true);
45 curl_setopt($ch, CURLOPT_HEADER,
true);
46 $chResp = curl_exec($ch);
47 $message->ok = $chResp !==
false;
49 $chResp = str_replace(
"\r\n",
"\n", $chResp);
50 $chRespSplit = explode(
"\n\n", $chResp, 2);
51 if ((count($chRespSplit) > 1) && (substr($chRespSplit[1], 0, 5) ===
'HTTP/')) {
52 $chRespSplit = explode(
"\n\n", $chRespSplit[1], 2);
54 $message->responseHeaders = $chRespSplit[0];
55 $message->response = $chRespSplit[1];
56 $message->status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
57 $message->ok = $message->status < 400;
59 $message->error = curl_error($ch);
62 $message->requestHeaders = str_replace(
"\r\n",
"\n", curl_getinfo($ch, CURLINFO_HEADER_OUT));
getUrl()
Get the target URL for the request.
getMethod()
Get the HTTP method for the request.
send(HTTPMessage $message)
Send the request to the target URL.
Class to implement the HTTP message interface using the Curl library.
Class to represent an HTTP message request.
Interface to represent an HTTP message client.