Sends data to a web server using the POST action of HTTP.Syntax:
post <data> to URL <destinationURL>
put "name=max" into myData post myData to URL "http://www.example.net/indications.cgi"
post field "Return Values" to URL field "Current Page"
post tData to URL tMyUrl
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".
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:email@example.com/"
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 "firstname.lastname@example.org" into userPassword put "http://" & userName & ":" & URLEncode(userPassword) & "@www.example.net/index.html" into fileURLToGet get URL fileURLToGet
You can test your post code with:
post "hello world" to URL "http://posttestserver.com/post.php" launch URL (word -1 of line 2 of it)
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.
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. 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 (https://tools.ietf.org/html/rfc1738). Ensure that you URLEncode any username and password fields appropriately for FTP URLs.
- data: Any text that evaluates to a string.
- destinationURL: The URL where the data is to be sent.
- It: The value the web server returns is placed in the it variable.
- The result: If an error occurs, the result function is set to the error message.
Important: If a blocking operation involving a URL (using: the put command to upload a URL, the post command, the delete URL command, or a statement that gets an ftp or HTTP URL) is going on, no other blocking URL operation can start until the previous one is finished. If you attempt to use a URL in an expression, or put data into a URL, while another blocking URL operation is in progress, the result is set to "Error Previous request not completed".
See also: delete URL (command),read from socket (command), put (command), libURLSetExpect100 (command), libURLSetLogField (command),open socket (command), libURLSetCustomHTTPHeaders (command), result (function), URLStatus (function), URLEncode (function), libURLFormData (function), URLDecode (function), libURLMultipartFormAddPart (function), libURLMultipartFormData (function), urlProgress (message), httpHeaders (property), HTTPProxy (property)