PREPAREPOST        Builds an HTTP/HTTPS POST Request

<< Click to Display Table of Contents >>

Navigation:  Robo-FTP User's Guide > Script Programming > Script Commands > All Script Commands >

PREPAREPOST        Builds an HTTP/HTTPS POST Request

Syntax:

PREPAREPOST

[ content-type ]

Arguments:

[ content-type ]

HTTP Content-Type header. Supported types are "multipart/form-data" and

"application/x-www-form-urlencoded"

Options:

none

 

 

 

This script command helps you programmatically build an HTTP/HTTPS POST Request body for automating the submission of the most common type of web forms.  Requests prepared with this command are typically submitted via the HTTPPOST command.    

 

The default value of [ content-type ] is "multipart/form-data" which is the more complex but more capable of the available options. This is the only content type able to POST to web forms that upload files.  The value specified in the [ content-type ] argument replaces the value of the /contenttype option on the HTTPPOST command.

 

After using this command to create the Request, use the POSTVALUE script command to add name/value pairs to the prepared POST data.  Finally you submit the Request using the HTTPPOST command with the /intype=prepared option.

 

The following example sends a POST request to a hypothetical HTTP service at "https://www.example.com/api/v2/edit_user_info.php" and stores the response in the "response_var" variable:

 

FTPLOGON "www.example.com" /servertype=https /allowerrors

FTPCD "/api/v2"

PREPAREPOST "application/x-www-form-urlencoded"

POSTVALUE "apikey" "D73B04B0E696B0945283DEFA3EEE4538"

POSTVALUE "sessionid" "YmVzdXJldG9kcmlua3lvdXJvdmFsdGluZQ=="  

POSTVALUE "userid" "2295793"

POSTVALUE "name" "First Middle Last"

HTTPPOST "edit_user_info.php" "" response /intype=prepared /outtype=string

 

The following example uploads a file to a hypothetical HTTP service at "https://www.example.com/upload". This service expects a multipart/form-data POST with a field named "file" containing the file data:

 

FTPLOGON "www.example.com" /servertype=https /allowerrors

PREPAREPOST "multipart/form-data"

POSTVALUE "file" "1542286841337.jpg" /file /contenttype="binary/octet-stream"

HTTPPOST "upload" "" "my_http_response.txt" /intype=prepared

 

Related command(s): POSTVALUE, HTTPPOST

See also: HTTP Considerations