TestKeks
8 years agoOccasional Contributor
Performing post request with content-type multipart/form-data (for binary file)
Hi,
in a script test, I would like to use the send method to send a binary file, namely a desktop screenshot, formatted in the content type "multipart/form-data". According to the JavaScript code example for the CreatePostRequest Method I wrote down the following:
function httpPostRequest()
{
var address = "https://example.com/receiver";
// Define the request body FormData-Object
var requestBody = new FormData(Sys.Desktop.Picture());
// Create the aqHttpRequest object
var aqHttpRequest = aqHttp.CreatePostRequest(address, "", "");
// Specify the Content-Type header value
aqHttpRequest.SetHeader("Content-Type", "multipart/form-data");
// Send the request, create the aqHttpResponse object
var aqHttpResponse = aqHttpRequest.Send(requestBody);
// Check the response:
Log.Message(aqHttpResponse.StatusCode); // A status code
Log.Message(aqHttpResponse.Text); // A body
}
But the JavaScript object FormData, which is to be generated in this code, is apparently not supported by TestComplete. The error "ReferenceError: FormData is not defined" appears. Or what am I doing wrong?
Is there any other way? Or do I have to build my own function to format the binary code according to the standard (see here)?
Thanks in advance for any hint and best regards