Description
Fetch or post something with http, ftp or imap.
Examples
[%$html = fetch("https://www.topincs.com/tour");%]
[%// Report current coordinates of truck.
fetch(
url: "https://www.somewhere.com/coordinates?apikey=secret",
method: "POST",
body: sprintf(
"lon=%s&lat=%s",
$truck->get_longitude(),
$truck->get_latitude()
)
); %]
[%$txt = fetch("ftp://Jim:1234@ftp.example.com/readme.txt");%]
[%// FTP file upload.
fetch(
url: "sftp://Jim:1234@ftp.example.com/newfile.txt",
method: "POST",
body: "Hello, there!",
);%]
[%// FTP: iterating over a remote folder, yields plain objects.
foreach (fetch("ftp://Jim:1234@ftp.example.com/dir/") as $file) { ?>
if (strpos($file->filename, ".csv") > 0) {
Tobject::make_OrdersCsvFile(tmp_file($file->contents));
}
} %]
[%// IMAP: iterating over a remote folder, yields plain objects.
foreach (fetch("imaps://Jim:12345@imap.example.com/INBOX/Invoices/" as $mail) {
if ($mail->to === "invoice@example.com") {
foreach ($mail->attachments as $part) {
Tobject::make_InvoiceFile(tmp_file($part->contents), $part->filename);
}
}
});%]
[%// In case the remote server has a SSL problem.
fetch("https:://short.co/abc", options: [CURLOPT_SSL_VERIFYPEER => false]);%]
|
Parameters10
Coding name |
url
|
Position |
1
|
Type |
String(Primitive type)
|
Coding name |
method
|
Description |
The HTTP verb, GET or POST.
|
Position |
2
|
Type |
String(Primitive type)
|
Default value |
GET
|
Coding name |
body
|
Description |
The body of the request to send.
|
Position |
3
|
Type |
String(Primitive type)
|
Default value |
The empty string, so no body is sent.
|
Coding name |
headers
|
Description |
Headers to send with the request.
|
Position |
4
|
Type |
Array(Primitive type)
|
Default value |
The empty array, so no headers are sent.
|
Coding name |
timeout
|
Description |
Timeout in seconds.
|
Position |
5
|
Type |
Integer(Primitive type)
|
Default value |
10 seconds.
|
Coding name |
debug
|
Description |
Detailed information will be written to debug.
|
Position |
6
|
Type |
Boolean(Primitive type)
|
Default value |
False, no debug inforamation is written.
|
Coding name |
public_key
|
Description |
A Topincs file holding the public key.
|
Position |
7
|
Type |
Tobject(PHP class)
|
Coding name |
private_key
|
Description |
A Topincs file holding the private key.
|
Position |
8
|
Type |
Tobject(PHP class)
|
Coding name |
location
|
Description |
Just get the location of a redirect response.
|
Position |
9
|
Type |
Boolean(Primitive type)
|
Coding name |
options
|
Description |
Additional options for CURL.
|
Position |
10
|
Type |
Array(Primitive type)
|
|