httpWrite | Multi Theft Auto: Wiki Skip to content

httpWrite

Client-side
Server-side
Shared
Needs checking

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

  • Missing section: Shortcut syntax

Manual Review Required

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


This function adds text to the output of the current HTTP file of the HTTP interface. The function can only be used on parsed (i.e not marked as raw) HTTP pages. httpWrite can support outputing binary data, if you specify the length of the data you are outtputing. If you do this, you should ensure you set an accurate content-type using httpSetResponseHeader otherwise it may be displayed inconsistently by browsers.

Syntax

bool httpWrite ( string data, int length )
Required Arguments
  • data: the data to be added to the page's output.
  • length: The length of the data being written. Generally only should be required for writing binary data.

Returns

  • bool: value

Returns true if the text was added to the output buffer successfully, false otherwise.

Code Examples

shared

Example 1:This sample resource page will output a random quote from a player using a function previously exported to http from a Lua script in the resource.

[html]
<html>
<head>
<* = call ( getResourceFromName("ajax"), "start", getResourceName(getThisResource()) ) *>
</head>
<body>
<b>Random quote:</b> <* httpWrite( call ( getThisResource(), "getRandomQuote" ) ) *>
</body>
</html>