HTTP Stream to File
Sends an HTTP request by using a GET method to a specified URL and saves the response in a TMP
file.
By default the TMP
file is saved to the %localappdata%\Temp\
folder.
Terms | Description |
---|---|
HTTP request | A client makes an HTTP request to access or modify a resource on a server. |
GET | The GET method requests data from a specific resource. Requests with the GET method only return data. |
URL | A URL (Uniform Resource Locator) is a specific type of URI (Universal Resource Identifier). A URL normally locates an existing resource on the Internet. It is used to identify the target server. |
TMP file | A temporary file, usually with the .tmp extension. |
Syntax
IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.
httpStreamToFile --url(String) [--headers(StringDictionary<String>)] [--username(String)] [--password(String)] [--timeout(TimeSpan)] (Boolean)=success (String)=value (Numeric)=statusCode (String)=reasonPhrase (StringDictionary<String>)=headers (StringDictionary<String>)=contentHeaders
Input parameters
The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.
Designer mode label | Script mode name | Required | Accepted variable types | Description |
---|---|---|---|---|
URL | url |
Required |
Text |
URL for submitting the request. |
Headers | headers |
Optional |
String Dictionary<Text> |
The headers of the request with the necessary information to complete the request. Mandatory header fields are generally documented on the resource's API documentation. |
User Name | username |
Optional |
Text |
Network credential user. Parameter used for proxy authentication. |
Password | password |
Optional |
Text |
Network credential password. Parameter used for proxy authentication. |
Timeout | timeout |
Optional |
Time Span , Number , Text |
Maximum wait time for response. The default timeout is 5 seconds. It can also use the timeout defined by the Set Timeout (setTimeout ) command. |
Output parameters
Designer mode label | Script mode name | AcceptedTypes | Description |
---|---|---|---|
Success | success |
Boolean |
Returns True if the reponse status code is 2xx. Otherwise, returns False . |
File | value |
Text |
Returns the full path to the .tmp file. |
Status Code | statusCode |
Number |
Returns the HTTP request status code. See statusCode parameter options for details. |
Reason Phrase | reasonPhrase |
Text |
Returns a short textual description of the status code. |
Headers | headers |
String Dictionary<Text> |
Returns the response headers of the request. |
Content Headers | contentHeaders |
String Dictionary<Text> |
Returns the response content headers of the request. |
statusCode
parameter options
The following table displays the possible status code responses to the request:
Response code | Description |
---|---|
1xx | Information responses. |
2xx | Successful responses. |
3xx | Redirection messages. |
4xx | Request errors. |
5xx | Errors on the server. |
If you want to learn more, see Status code 🡥 for details.
Examples
Example 1: The following example shows how to use the HTTP Stream to File to get a file from APIs, in this case one image gif. The script gets the desktop folder path to save the gif on it. Then, a request is made to the API, creating the temporary file. And finally, the file is renamed and pasted on the desktop folder.
defVar --name success --type Boolean
defVar --name catFilePath --type String
defVar --name returnedStatusCode --type Numeric
defVar --name reasonPhrase --type String
defVar --name responseHeaders --type StringDictionary --innertype String
defVar --name responseContentHeaders --type StringDictionary --innertype String
defVar --name desktopFolderPath --type String
//--------------------------------About this script--------------------------------
//Description: This script gets an image and saves it to your Desktop folder
//Last updated: 02/01/2023
//-----------------------------------------------------------------------------------
getSpecialFolder --folder "Desktop" --comment "Gets the desktop folder path" desktopFolderPath=value
logMessage --message "Obtained desktop folder path: ${desktopFolderPath}" --type "Info"
httpStreamToFile --url "https://cataas.com/cat/gif" --comment "Make a GET HTTP request to https://cataas.com/cat/gif and save the response in a TEMP file " success=success returnedStatusCode=statusCode reasonPhrase=reasonPhrase responseHeaders=headers responseContentHeaders=contentHeaders catFilePath=value
logMessage --message "Request made to \"https://cataas.com/cat/gif\". It returns:\r\nSuccess: ${success}\r\nStatus code: ${returnedStatusCode}\r\nReason phrase: ${reasonPhrase}\r\nResponse headers: ${responseHeaders}\r\nResponse content headers: ${responseContentHeaders}\r\nPath to the temp file: ${catFilePath}" --type "Info"
fileRename --file "${catFilePath}" --newname "cat.gif" --comment "Renaming and setting the correct extension to the file" catFilePath=value
logMessage --message "Temp file renamed to cat.gif" --type "Info"
fileMove --from "${catFilePath}" --to "${desktopFolderPath}" --comment "Move the file to the desktop"
logMessage --message "File moved to your descktop: ${catFilePath}" --type "Info"
Example 2: The following example shows how to use the HTTP Stream to File to get a file from any URL, in this case this command documentation in HTML. The script gets the desktop folder path to save the documentation in this directory. Then, sends the request to the URL, creating the temporary file. And finally, renames and saves the file on the desktop folder.
defVar --name success --type Boolean
defVar --name httpStreamToFileFilePath --type String
defVar --name returnedStatusCode --type Numeric
defVar --name reasonPhrase --type String
defVar --name responseHeaders --type StringDictionary --innertype String
defVar --name responseContentHeaders --type StringDictionary --innertype String
defVar --name desktopFolderPath --type String
//--------------------------------About this script--------------------------------
//Description: This script gets an HTML file from IBM Docs
//Last updated: 02/01/2023
//-----------------------------------------------------------------------------------
getSpecialFolder --folder "Desktop" --comment "Gets the desktop folder path" desktopFolderPath=value
logMessage --message "Obtained desktop folder path: ${desktopFolderPath}" --type "Info"
httpStreamToFile --url "https://www.ibm.com/docs/en/rpa/23.0?topic=web-http-stream-file" --comment "Make a GET HTTP request to https://www.ibm.com/docs/en/rpa/23.0?topic=web-http-stream-file and save the response in a TEMP file " success=success returnedStatusCode=statusCode reasonPhrase=reasonPhrase responseHeaders=headers responseContentHeaders=contentHeaders httpStreamToFileFilePath=value
logMessage --message "Request made to \"https://www.ibm.com/docs/en/rpa/23.0?topic=web-http-stream-file\". It returns:\r\nSuccess: ${success}\r\nStatus code: ${returnedStatusCode}\r\nReason phrase: ${reasonPhrase}\r\nResponse headers: ${responseHeaders}\r\nResponse content headers: ${responseContentHeaders}\r\nPath to the temp file: ${httpStreamToFileFilePath}" --type "Info"
fileRename --file "${httpStreamToFileFilePath}" --newname "HTTP Stream to File.html" --comment "Renaming and setting the correct extension to the file" httpStreamToFileFilePath=value
logMessage --message "Temp file renamed to HTTP Stream to File.html" --type "Info"
fileMove --from "${httpStreamToFileFilePath}" --to "${desktopFolderPath}" --comment "Move the file to the desktop"
logMessage --message "File moved to your descktop: ${httpStreamToFileFilePath}" --type "Info"