5.3.x

Some functionality was added to HttpRequest and the third party libraries htmlunit and htmlunit-driver were updated.

XLT 5.3.0

See here for the complete list of improvements and fixes.

Test Framework

Update 3rd-party libraries

The 3rd-party libraries htmlunit and htmlunit-driver have been updated to version 2.46.

HttpRequest: Support binary request bodies

The class HttpRequest simplifies making HTTP requests to a server. For PUT, POST, and PATCH requests, the request body may contain custom data to be sent to the server. Up to now, HttpRequest supported only strings as the request body, which is sufficient for JSON or similar formats, but not for binary data of any sort. Now HttpRequest comes with additional overloads of the body(...) method to set binary content from different sources as the request body:

  • body(byte[])
  • body(File)
  • body(InputStream)

See below for some example code how to put the content of a binary file into the body of a PUT request:

HttpRequest httpRequest = new HttpRequest();

httpRequest.timerName("Upload");
httpRequest.baseUrl(UPLOAD_URL);
httpRequest.method(HttpMethod.PUT);
httpRequest.header("Content-Type", "application/gzip");
httpRequest.body(new File("/tmp/123.tar.gz"));

httpRequest.fire();

HttpRequest: Support file upload

In general, files can also be uploaded to a server as multi-part form data in a POST request. HttpRequest supports this mode now as well. All you need to do is populate a KeyDataPair instance with the file to upload and additional meta data and pass it as parameter to the HttpRequest:

HttpRequest httpRequest = new HttpRequest();

httpRequest.timerName("FileUpload");
httpRequest.baseUrl(UPLOAD_URL);
httpRequest.method(HttpMethod.POST);
httpRequest.encodingType(FormEncodingType.MULTIPART);
httpRequest.param(new KeyDataPair("file", "/tmp/123.tar.gz", "123.tar.gz", "application/gzip", StandardCharsets.UTF_8));

httpRequest.fire();

Make sure you use HTTP method POST and also specify MULTIPART as the form encoding for file uploads to work.

Last modified May 25, 2022