Livecode Wiki
Advertisement

Respond to a HTTP request when the internal livecode http server is running (launched by httpdstart).

Built-in Message handler[]

Syntax

httpdResponse pSocketID,pResponseCode,pContent,pHeaders

Parameters

  • pSocketID: The socket ID sent to the request callback
  • pResponseCode: A HTTP response code. See https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for more detail.
  • pContent: This is the content to respond to the request with.
  • pHeaders: Any additional headers to send with the response. Content-Length, Server, Date and Connection are set by default.

Example

start using stack "httpd"

on mouseUp
  httpdStart "NewRequest", 12345, "My Server"
  launch url ("http://localhost:" & it)
end mouseUp

on NewRequest pSocketID, pRequest
  put the effective filename of this stack into tPath
  set the itemDelimiter to tPath
  put "files/" & pRequest["resource"] into the last item of tPath
  if there is a file tPath then
     put url ("binfile:" & tPath) into tData
     httpResponse pSocketID, 200, tData
  else
     -- not found
     httpResponse pSocketID, 404
  end if
end NewRequest

Handle the callback set when starting the server and respond to the request according to your requirements.

See also: httpdstart, httpdstop

Advertisement