New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to raw response in test scripts? #2024

Closed
bricker opened this Issue Apr 27, 2016 · 1 comment

Comments

3 participants
@bricker

bricker commented Apr 27, 2016

Hello, I'm using the Mac app (version 4.1.1) on OS X 10.11.5.

I have a response which is encrypted and sent to me as raw bytes. I am trying to decrypt this response from within the test script, and in order to do this I need access to that raw response. But, it seems that the responseBody string is being converted to a string which is losing some data.

I am currently inspecting the bytes with this:

for (var i = 0; i < responseBody.length; ++i) {
    console.log(responseBody.charCodeAt(i));
}

For example, the response might have a byte "0xb3", but using the code above I only get back 65533, i.e. "unrecognized character".

When downloading the binary data as a file (via "Send and Download"), the data is correct, I think because in that case the XmlHttpRequest is sent with response type of "arrayBuffer". But I can't run tests on that downloaded data from within postman, which is the whole point of decrypting the data.

So, is there a way to access the raw response body, possibly as an array buffer, from within the test script? Or is there another way for me be able to decrypt and run tests on this type of response?

Thanks!

@bricker bricker changed the title from Access to raw response in tests scripts? to Access to raw response in test scripts? Apr 27, 2016

@abhijitkane abhijitkane added the support label Apr 27, 2016

@abhijitkane

This comment has been minimized.

Show comment
Hide comment
@abhijitkane

abhijitkane Sep 11, 2017

Member

@bricker Starting version 5.2.0, you can use pm.response.stream:

console.log(pm.response.stream);
function arrayBufferToString(buffer){
    var arr = new Uint8Array(buffer);
    var str = String.fromCharCode.apply(String, arr);
    if(/[\u0080-\uffff]/.test(str)){
        throw new Error("this string seems to contain (still encoded) multibytes");
    }
    return str;
}
console.log(arrayBufferToString(pm.response.stream));
Member

abhijitkane commented Sep 11, 2017

@bricker Starting version 5.2.0, you can use pm.response.stream:

console.log(pm.response.stream);
function arrayBufferToString(buffer){
    var arr = new Uint8Array(buffer);
    var str = String.fromCharCode.apply(String, arr);
    if(/[\u0080-\uffff]/.test(str)){
        throw new Error("this string seems to contain (still encoded) multibytes");
    }
    return str;
}
console.log(arrayBufferToString(pm.response.stream));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment