Testing STOMP websocket with Postman
Daniel Schreiber

Daniel Schreiber @danielsc

Location:
Offenbach, Germany
Joined:
Jul 19, 2019

Testing STOMP websocket with Postman

Publish Date: Aug 12 '21
21 7

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!

Comments 7 total

  • rangoy
    rangoyOct 29, 2021

    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
    • Daniel Schreiber
      Daniel SchreiberOct 29, 2021

      Nice!

      • fmaillard-tbs
        fmaillard-tbsSep 20, 2022

        So how to use

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

        with Websockets ? Somebody succeded it ?

    • Aleksandr Putilov
      Aleksandr PutilovDec 10, 2021

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

    • limaral394@laluxy.com
      limaral394@laluxy.comSep 12, 2022

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

  • benayat
    benayatMar 6, 2023

    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

  • mrichardsonjr
    mrichardsonjrAug 15, 2023

    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.)

Add comment