2.1 KiB
RequestPost()
The RequestPost() command performs an HTTP POST request to a specified URL, sending a query string, headers, and a request body, and stores the result of the request in a destination variable. This command is useful for sending data to a server and handling the responses from the request.
Parameters
- url Type:
variableDescription: The URL to which the POST request will be sent. It should be a variable containing the address of the resource to which the request is to be made. - querystring Type:
variableDescription: The query string that will be appended to the URL. It should be a variable containing the query parameters in string format. - headers Type:
variableDescription: The HTTP headers that will be included in the POST request. It should be a variable containing a dictionary of headers and their values. - body Type:
variableDescription: The body of the POST request that will be sent to the server. It should be a variable containing the data to be sent in the request. - o_result Type:
variableDescription: The variable in which the result of the POST request will be stored. It should be a variable that will receive the server's response.
Command Flow
Example Usage
Suppose you want to send a POST request to https://api.example.com/data , with a query string userId=123 , headers including Content-Type: application/json , and a body with JSON data.
// Define variables
url = "https://api.example.com/data"
querystring = "userId=123"
headers = {"Content-Type": "application/json"}
body = '{"name": "Alice", "age": 30}'
response = ''
// Call the command to perform the POST request
RequestPost(url, querystring, headers, body, response)
// Return the request result via addResult
addResult(response)
In this example, the RequestPost() command will send a POST request to https://api.example.com/data with the provided query string, headers, and body. The server's response will be stored in the response variable, and this variable will be returned via addResult(response) . The result of the request will be included in the final response.