HttpRequest
in package
This is the HttpRequest class.
This class is the responsible to execute http requests.
Tags
Table of Contents
__construct() | Constructor. | : mixed |
---|---|---|
getInfo() | Returns curl information options that were stored when the request was sent | : array<string|int, mixed> |
send() | Send the request to the setted URL. | : array<string|int, mixed> |
setBody() | Set the request body. | : void |
setCookies() | Set the cookies to send on the request. | : void |
setCurlInfoOptions() | Sets curl info options that will be store when sends the request | : void |
setData() | Set form (POST) parameters on the request. | : void |
setHeader() | Add a new header to the request. | : void |
setHeaders() | Add a new headers to the request. | : void |
setParams() | Set URL (GET) parameters on the request. | : void |
setTimeout() | Set the request timeout (the maximum time the request will wait for response). | : void |
setUserAgent() | Set the request user-agent. | : void |
Methods
__construct()
Constructor.
public
__construct(string $url[, string $method = 'get' ]) : mixed
This will prepare the object to made the request.
Parameters
- $url : string
-
request URL to call
- $method : string = 'get'
-
HTTP method
Return values
mixed —getInfo()
Returns curl information options that were stored when the request was sent
public
getInfo() : array<string|int, mixed>
Return values
array<string|int, mixed> —send()
Send the request to the setted URL.
public
send() : array<string|int, mixed>
The return will be an array with the following structure:
- result -> the request content (body)
-
status -> the request status information
- code -> the request response code
- message -> the request response message
Tags
Return values
array<string|int, mixed> —setBody()
Set the request body.
public
setBody(string $body) : void
Parameters
- $body : string
Return values
void —setCookies()
Set the cookies to send on the request.
public
setCookies(array<string|int, mixed> $cookies) : void
Parameters
- $cookies : array<string|int, mixed>
-
Array containing the cookies you want to send on the request.
Return values
void —setCurlInfoOptions()
Sets curl info options that will be store when sends the request
public
setCurlInfoOptions(array<string|int, mixed> $options) : void
Parameters
- $options : array<string|int, mixed>
Return values
void —setData()
Set form (POST) parameters on the request.
public
setData(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
-
Array containing the values you want to set as POST parameters on the request.
Return values
void —setHeader()
Add a new header to the request.
public
setHeader(string $key, mixed $value) : void
Parameters
- $key : string
-
Name of the header you want to set the value.
- $value : mixed
-
The value you want to set on the given header key.
Return values
void —setHeaders()
Add a new headers to the request.
public
setHeaders(array<string|int, mixed> $headers) : void
Parameters
- $headers : array<string|int, mixed>
-
Headers to add to the request.
Return values
void —setParams()
Set URL (GET) parameters on the request.
public
setParams(array<string|int, mixed> $params) : void
Parameters
- $params : array<string|int, mixed>
-
Array containing the values you want to set as GET parameters on the request.
Return values
void —setTimeout()
Set the request timeout (the maximum time the request will wait for response).
public
setTimeout(int $timeout) : void
Parameters
- $timeout : int
Return values
void —setUserAgent()
Set the request user-agent.
public
setUserAgent(string $userAgent) : void
Parameters
- $userAgent : string