dd / evolutioncms-snippets-ddmakehttprequest
Makes HTTP request to a given URL.
Installs: 6
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:modxevo-snippet
Requires
- php: >=5.6.0
- dd/modxevo-library-ddtools: >=0.48.2
This package is auto-updated.
Last update: 2024-11-06 08:13:03 UTC
README
Makes HTTP request to a given URL.
Supports redirects even if native CURL redirects is unavailable.
Requires
- PHP >= 5.6
- (MODX)EvolutionCMS.libraries.ddTools >= 0.48.2
Documentation
Installation
1. Elements → Snippets: Create a new snippet with the following data
- 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.
2. Elements → Manage Files
- Create a new folder
assets/snippets/ddMakeHttpRequest/
. - Extract the archive to the folder (except
ddMakeHttpRequest_snippet.php
).
Parameters description
-
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
Examples
Simple GET request
[[ddMakeHttpRequest?
&url=`http://www.example.com?name=John&surname=Doe`
]]
Simple POST request
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`
]]
Run the snippet through \DDTools\Snippet::runSnippet
without DB and eval
\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' ] ]);