I am trying in my test scripts to compute message digests on response bodies data to validate them.
I am using the pm.response.text() to compute the message digests.
That works as long as the body contains ASCII data.
But as soon as the body contains data other than ASCII, it does not work anymore as expected.
The problem occurs because the content returned by pm.response.text() is not the raw data, but is somehow modified.
I use the following code to verify the message digest and the content of pm.response.text() as an hexadecimal representation:
var rawBody = pm.response.text();
var hexBody = ββ;
for (i = 0; i <rawBody.length; i ++) {
hexBody += rawBody.charCodeAt(i).toString(16);
}
console.log("MD5: " + CryptoJS.enc.Hex.stringify(CryptoJS.MD5(pm.response.text())));
console.log("Hexa data: " + hexBody);
For a received body with one β0x61β byte (which is βaβ in ASCII), I get the following displayed in the console:
βMD5: 0cc175b9c0f1b6a831c399e269772661β
βHex data: 61β
For a received body with one β0x97β byte, I get the following displayed in the console, which is obviously wrong (MD5 should be c444b580079efb1fe408f17f029e5d35):
βMD5: 9b759040321a408a5c7768b4511287a6β
βHexa data: fffdβ
How can I get the unmodified response raw body (or decoded if I received deflated, gziped, etc. content) ?
I had a similar question and got this response from Postman team. Posting it hear to help others. Itβs not a great answer, but it might help depending on your situation.
As I understand it, you would like to parse a PDF file and then calculate MD5 value, correct?
According to my search, it seems that there is no method that can directly parse a PDF file. However I found a workaround that can be implemented in the backend shown in this YouTube channel: https://www.youtube.com/watch?v=zwfwJ165zHw
To get raw binary data there is a way in postman by extracting stream of data from pm.response object. You can use below snippet to extract the data and specify the byte stream.