Hi,
for some reason, I am able to run a Pre-request script and set up a Collection Variable (for setting up a token) for REST requests, but when I have the same script run as a Before Invoke
script in a gRPC request it fails with the error message:
code: “ECONNRESET”
name: “Error”
message: “socket hang up”
stack: “Error: socket hang up
at connResetException (node:internal/errors:691:14)
at TLSSocket.socketOnEnd (node:_http_client:471:23)
at TLSSocket.emit (node:events:402:35)
at TLSSocket.emit (node:domain:475:12)
at endReadableNT (node:internal/streams/readable:1343:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)”
Do you have any idea why? what am I doing wrong?
Thank you,
Bar.
@shabib can you share the script that we can use to reproduce this issue locally?
@udit.vasu - there you go
const options = {
url: “https://[[SOME_URL]]/token”,
method: ‘POST’,
header: { ‘content-type’: ‘application/json’ },
body: {
mode: ‘raw’,
raw: JSON.stringify([[BODY_PAYLOAD]])
}
};
pm.sendRequest(options, function (err, response) {
if (err) {
console.error(err);
return;
}
const data = response.json();
console.info(data);
pm.collectionVariables.set("jwt", data.token);
});
The following code snippet works fine for me.
const options = {
url: "https://postman-echo.com/post",
method: "POST",
header: { "content-type": "application/json" },
body: {
mode: "raw",
raw: JSON.stringify({ token: "foobar" })
}
};
pm.sendRequest(options, function (err, response) {
if (err) {
console.error(err);
return;
}
const data = response.json();
console.info(data);
pm.collectionVariables.set("jwt", data.token);
});
I wonder if it might be because there is a bug in picking up the local certificate I set in the Certificate Setting for the URL I use. can you help me check for that?