DEV Community

Daniel Schreiber
Daniel Schreiber

Posted on • Updated on

Testing STOMP websocket with Postman

With Postman v8 you can test Websockets - great! But..

When testing STOMP servers you will encounter a problem:

The body is then followed by the NULL octet.

See https://stomp.github.io/stomp-specification-1.2.html#STOMP_Frames

The only way (on windows) to get the NULL octet into the frame is by using the "binary/Base64" encoding (see screenshot below).

image

To easily convert the frame you can use Notepad++:

  1. Activate "Character Panel"
  2. Add "NULL" at the end of the frame (after all headers and body) - make sure to actually click on "NULL"
  3. Select complete frame and encode it to Base64

image

image

If you found an easier way, please comment!

Top comments (7)

Collapse
 
rangoy profile image
rangoy • Edited

Hi, thank you for your tips.

Inspired by your effort I found a way of adding the NULL char at the end:
It's not beautiful, but less hassle than going through base64 encoding

  1. Use a pre-request Script in an other collection (as websocket collections doesn't yet support scripts) set a variable, eg NULL_CHAR. I use the same script to get a token too.
pm.environment.set('NULL_CHAR', '\0');
Enter fullscreen mode Exit fullscreen mode
  1. Run a request in the other collection to get the token and set the variables,
  2. Use the token and variables in the messages, eg. Make sure you do not add a newline after NULL_CHAR
CONNECT
Authorization:Bearer {{TOKEN}}
accept-version:1.1,1.0
heart-beat:10000,10000

{{NULL_CHAR}}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
putilovai profile image
Aleksandr Putilov • Edited

Setting environment variable didn't work for me. I used global variables
pm.globals.set("NULL_CHAR", '\0');

Collapse
 
limaral394 profile image
limaral394@laluxy.com • Edited

For linux, setting NULL_CHAR as ^@ worked for me.
pm.globals.set("NULL_CHAR",'^@')

Collapse
 
danielsc profile image
Daniel Schreiber

Nice!

Collapse
 
fmaillardtbs profile image
fmaillard-tbs

So how to use

pm.globals.set("NULL_CHAR", '\0');

with Websockets ? Somebody succeded it ?

Collapse
 
benayat profile image
benayat

if you want something easier and user friendly, use apic to test your websocket with stomp. just a chrome extention, it works out of the box: docs.apic.app/tester/test-websocket

Collapse
 
javadeveloper008 profile image
mrichardsonjr

Mr. Schreiber, I don't use the word "hero" lightly, but you are the greatest hero in American history. (Thank you for saving me hours of beating my head against the wall.)