fetchRemote | Multi Theft Auto: Wiki Skip to content

fetchRemote

Client-side
Server-side
Shared
Needs checking

This function was partially migrated from the old wiki. Please review manually:

  • Missing section: CallbackstatusCodeerror values

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function allows you to post and receive data from HTTP servers. The calls are asynchronous so you do not get an immediate result from the call, instead a callback function you specify is called when the download completes.

Note

Client side function only works with the server the player is connected to unless the domain has been accepted with requestBrowserDomains

Caution

function won't trigger inside another fetchRemote function

Caution

When using toJSON for submitting data, make sure to use string.sub(data, 2, -2) to remove the initial and final brackets, as many APIs will not understand the request

Syntax

fetchRemote ( )

Code Examples

server

Sending email via a web service (adopted from examples onhttps://documentation.mailgun.com/en/latest/user_manual.html)

sendOptions = {
queueName = "My Mailgun queue",
connectionAttempts = 3,
connectTimeout = 5000,
formFields = {
from="Excited User <[email protected]>",
to="[email protected]",
subject="Hello",
text="Testing some Mailgun awesomness!",
},
username="api",
password="key-3ax6xnjp29jd6fds4gc373sgvjxteol0",
}
fetchRemote( "https://api.mailgun.net/v3/samples.mailgun.org/messages", sendOptions, mailgunCompleteCallback )
function mailgunCompleteCallback(data, info)
outputDebugString( "mailgunComplete"
.. " success:" .. tostring(info.success)
.. " statusCode:" .. tostring(info.statusCode)
.. " data:" .. tostring(data)
)
end