Skip to main content

post

Type

command

Summary

Sends data to a web server using the POST action of HTTP.

Syntax

post <data> to URL <destinationURL>

Description

Use the post command to submit data to a web server.

Data you send should be encoded using the URLEncode function.

The HTTP header sent with the POST request can be changed using either the HTTPHeaders property or the libURLSetCustomHTTPHeaders command. By default, the "Content-Type" header line is set to "application/x-www-form-urlencoded".

note

Sending data with the post command is a blocking operation: that is, the handler pauses until LiveCode is finished sending the data. Since contacting a server may take some time, due to network lag, URL operations may take long enough to be noticeable to the user.

To send a username and password with the post command, use the standard syntax for including this information in a URL. For example, to access http://www.example.com/ with the username "me" and the password "pass", use the following statement :

    post someData to URL \"http://me:pass@www.example.com/\"
Important

If your user name or password contains any of the characters ":", "@", "/", ".", or "|", use the URLEncode function to safely encode the user name or password before putting them into the URL. The following example constructs a URL for a user whose password contains the "@" character:

    put \"name\" into userName
put \"jdoe@example.com\" into userPassword
put \"http://\" & userName & \":\" & URLEncode(userPassword) \
& \"@www.example.net/index.html\" into fileURLToGet
get URL fileURLToGet
Important

The post command is part of the Internet library on desktop platforms. To ensure that the command works in a desktop standalone application, you must include this custom library when you create your standalone. In the Inclusions pane of the Standalone Application Settings window, make sure the "Internet" script library is selected.

Cross-platform note

On iOS and Android, the post command is implemented in the engine. Therefore the Internet library is not needed to ensure the command works in a mobile standalone application. If included, the Internet library implementation will be used instead of the engine implementation. Note: The Android and iOS engines do not support 'libUrl' but do allow you to use post in the background. When specifying URLs for Android or iOS, you must use the appropriate form that conforms to RFC 1738. Ensure that you URLEncode any username and password fields appropriately for FTP URLs.

Parameters

NameTypeDescription

data

Any text that evaluates to a string.

destinationURL

The URL where the data is to be sent.

Examples

post myData to URL "http://www.example.net/indications.cgi"
post field "Return Values" to URL field "Current Page"
post tData to URL tMyUrl

message: urlProgress

property: httpHeaders, HTTPProxy

command: post, write to socket, delete URL, read from socket, put, libURLSetExpect100, libURLSetLogField, open socket, libURLSetCustomHTTPHeaders

control structure: function

function: result, URLStatus, URLEncode, libURLFormData, URLDecode, libURLMultipartFormAddPart, libURLMultipartFormData

glossary: variable, command, LiveCode custom library, property, standalone application, blocking, web server, command, expression, syntax, server, upload, statement, handler, Standalone Application Settings

keyword: URL, ftp, http

library: Internet library

Compatibility and Support

Introduced

LiveCode 1.0

OS

mac

windows

linux

ios

android

Platforms

desktop

server

mobile

Thank you for your feedback!

Was this page helpful?