'Get content length of Postman request including variable values

How do I programmatically get the content length of a Postman request INCLUDING variable values?

I need to include the content-length header in a PUT request I'm putting together in Postman. I can get the request content length in a pre-request script, however, according to the Postman script documentation, the pre-request script is (duh) getting the content length prior to the request being generated (or only sent?). This is problematic for my scenario, because I need the content length AFTER the variable values are filled in for the request.

//Get request length
var rdata = request.data;
var requestLength = JSON.stringify(JSON.parse(rdata)).length;
pm.environment.set("requestLength", requestLength);
console.log(requestLength);

content-length header



Solution 1:[1]

pm.environment.set("requestLength", request.data.length);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RainVision