Makes HTTP request to a given URL.
Supports redirects even if native CURL redirects is unavailable.
- PHP >= 5.6
- (MODX)EvolutionCMS.libraries.ddTools >= 0.48.2
- Snippet name:
ddMakeHttpRequest
. - Description:
<b>2.3.2</b> Makes HTTP request to a given URL.
. - Category:
Core
. - Parse DocBlock:
no
. - Snippet code (php): Insert content of the
ddMakeHttpRequest_snippet
file from the archive.
- Create a new folder
assets/snippets/ddMakeHttpRequest/
. - Extract the archive to the folder (except
ddMakeHttpRequest_snippet.php
).
-
url
- Desctription: The URL to fetch.
- Valid values:
string
- Required
-
method
- Desctription: Request type.
- Valid values:
'get'
'post'
- Default value:
'get'
-
postData
- Desctription: The full data to post in a HTTP “POST” operation.
- Valid values:
stringJsonObject
— as JSON objectstringHjsonObject
— as HJSONstringQueryFormated
— as Query stringstring
- It can also be set as a native PHP object or array (e. g. for calls through
\DDTools\Snippet::runSnippet
):arrayAssociative
object
- Default value: —
-
sendRawPostData
- Desctription: Send raw
postData
. E. g. if you need JSON in request payload. - Valid values:
0
1
- Default value:
0
- Desctription: Send raw
-
headers
- Desctription: An array of HTTP header fields to set.
- Valid values:
stringJsonArray
— as JSONstringHjsonArray
— as HJSONstringQueryFormated
— as Query string- It can also be set as a native PHP array (e. g. for calls through
\DDTools\Snippet::runSnippet
):array
- Default value: —
-
userAgent
- Desctription: The contents of the
User-Agent:
header to be used in a HTTP request. - Valid values:
string
- Default value: —
- Desctription: The contents of the
-
timeout
- Desctription: The maximum number of seconds for execute request.
- Valid values:
integer
- Default value:
60
-
proxy
- Desctription: Proxy server in format
[+protocol+]://[+user+]:[+password+]@[+ip+]:[+port+]
. E. g.http://user:password@11.22.33.44:5555
orsocks5://user:password@11.22.33.44:5555
. - Valid values:
string
- Default value: —
- Desctription: Proxy server in format
-
useCookie
- Desctription: Enagle cookies. The
assets/cache/ddMakeHttpRequest_cookie.txt
file is used. - Valid values:
0
1
- Default value:
0
- Desctription: Enagle cookies. The
[[ddMakeHttpRequest?
&url=`http://www.example.com?name=John&surname=Doe`
]]
Set data as JSON:
[[ddMakeHttpRequest?
&url=`http://www.example.com/`
&postData=`{
"name": "John",
"surname": "Doe"
}`
]]
Or Query string:
[[ddMakeHttpRequest?
&url=`http://www.example.com/`
&postData=`name=John&surname=Doe`
]]
\DDTools\Snippet::runSnippet([
'name' => 'ddMakeHttpRequest',
'params' => [
'url' => 'https://www.example.com/',
'postData' => [
'name' => 'John',
'surname' => 'Doe'
],
'headers' => [
'Accept: application/vnd.api+json',
'Content-Type: application/vnd.api+json'
],
'proxy' => 'socks5://user:password@11.22.33.44:5555'
]
]);