Seitenhistorie
...
Die URL ist das einzige Pflichtfeld.
Codeblock | ||||||
---|---|---|---|---|---|---|
| ||||||
local fetch = require("fetch") local response = fetch({ url = "https://webhook.site/", -- TODO: 'ne URL mit ID einfügen oder noch besser: Als Formular Feld konfigurierbar machen. method = "POST", headers = { ["content-type"] = "text/plain" }, body = "Test eines POST Requests im User-Script mit fetch.fetch" }) |
...
Shortcut für GET-Requests. options
ist eine optionale Tabelle mit den möglichen Eigenschaften headers
, follow_redirects
, timeout
und disable_certificate_validation
. Die Bedeutung der Eigenschaften ist im Abschnitt fetch.fetch
erklärt.
Codeblock | ||||||
---|---|---|---|---|---|---|
| ||||||
local fetch = require("fetch") local response = fetch.get("https://v2.jokeapi.dev/joke/Any?lang=de&format=txt&type=single&safe-mode") print(response.body) |
...
Das Argument options
ist im Abschnitt fetch.get
erklärt.
Codeblock | ||||||
---|---|---|---|---|---|---|
| ||||||
local fetch = require("fetch") local response = fetch.post( "https://webhook.site/...", -- TODO: URL mit ID einfügen oder besser: Im Formular als Feld einfügen { contentType = "application/json", data = "Test eines POST Request im User-Script mit fetch.post" } ) |
...
XML-String in eine Lua-Table konvertieren
Codeblock | ||||||
---|---|---|---|---|---|---|
| ||||||
local xml2lua = require("xml2lua") local handler = require("xmlhandler.tree") local xml = [[ <?xml version="1.0" encoding="UTF-8"?> <Table name="Einsatzdaten"> <Data type="STRING" header="Einsatznummer"/> <Data type="STRING" header="Einsatzstichwort"/> <Data type="STRING" header="Meldebild"/> <Row> <Column value="1234567890"/> <Column value="B2.5"/> <Column value="Rauchentwicklung in / aus Gebäude unklar"/> </Row> </Table> ]] local parser = xml2lua.parser(handler) parser:parse(xml) |
Lua-Table in einen XML-String konvertieren
Codeblock | ||||||
---|---|---|---|---|---|---|
| ||||||
local xml2lua = require("xml2lua") local incidents = { Table = { _attr = { name='Einsatzdaten' }, Data = { { _attr={ type='STRING', header='Einsatznummer' } }, { _attr={ type='STRING', header='Einsatzstichwort' } }, { _attr={ type='STRING', header='Meldebild' } } }, Row = { Column = { { _attr={ value='1234567890' } }, { _attr={ value='B2.5' } }, { _attr={ value='Rauchentwicklung in / aus Gebäude unklar' } } } } } } print("Incidents\n") xml2lua.printable(people) print() print("Incident Representation\n") print(xml2lua.toXml(incidents, "incidents")) |
...