Skip to content

httpWrite

Server-side
Caution

This function works only in the HTTP interface, meaning in .html files - it is not available in .lua files.

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.

Tip

You can use a shortened syntax, which looks like this:

<* = text *>

It is equivalent to:

<* httpWrite(text) *>

Syntax

bool httpWrite ( ​string data, [ ​int length = nil ] )
Required arguments
  • data: The data to be added to the page's output.
Optional arguments

Note: when using optional arguments, you might need to supply all arguments before the one you wish to use.

  • length (default: nil): The length of the data being written. Generally only should be required for writing binary data.

Returns

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

  • bool: result

Code Examples

server

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>
<head>
<* = call ( getResourceFromName("ajax"), "start", getResourceName(getThisResource()) ) *>
</head>
<body>
<b>Random quote:</b> <* httpWrite( call ( getThisResource(), "getRandomQuote" ) ) *>
</body>
</html>