Testing WebSocket API with Postman

James John 4 years ago

Hi
I want to test websocket API using Postman program, I created a session and I got the Session cookie.
But I don't where and how put the session cookie content inside postman.
The Header of Postman websocket contains hidden headers as follow:
*Host
*Connection
*Upgrade
*Sec-WebSocket-Key
*Sec-WebSocket-Version
*Sec-WebSocket-Extensions
and these header can't change of its values

Anton Tananaev 4 years ago

You should get the session cookie from a session API call.

James John 4 years ago

I GET the session that was
JSESSIONID : node0q90ykfyiwslpblv2x4y0s2qo0.node0

Where I should put it on websocket API ?

Anton Tananaev 4 years ago

The best way to find out is by looking at the official web app with browser developer tools (network tab).

James John 4 years ago

After I worked on it, the server response is:

Error: Unexpected server response: 200
Handshake Details
Status Code: 200 OK
Response Headers
Date: Wed, 25 Aug 2021 09:59:05 GMT
Last-Modified: Wed, 07 Jul 2021 13:32:31 GMT
Content-Type: text/html
Accept-Ranges: bytes
Cache-Control: max-age=3600,public
Content-Length: 610
Server: Jetty(10.0.3)
Anton Tananaev 4 years ago

URL and body?

James John 4 years ago
Anton Tananaev 4 years ago

I see a suspicious Socket.IO at the top. What does that mean?

James John 4 years ago

It is uses for enables real-time, bidirectional, and event-based communication between web clients and servers, using WebSockets under the hood.

Anton Tananaev 4 years ago

That's great, but Traccar doesn't use it.

James John 4 years ago

Can you send to me any tutorial for testing the websocket API, I am still working on it around two weeks but I can't get it.

Anton Tananaev 4 years ago

I just use web app and Chrome dev tools.

James John 4 years ago

Okay, thanks

Ledson Silva 4 years ago

I got it!!

Basically you need to create the session get the JSESSIONID and pass it via header in postman.

TESTE

jean jose de matos 4 years ago

I created the session, passed the session in the header and I get this error

HEAD ws://000.000.234.90:8082/api/socket
Error: Invalid protocol: ws:
Request Headers
User-Agent: PostmanRuntime/7.28.4
Accept: */*
Cache-Control: no-cache
Postman-Token: 717618d1-e27f-4c92-9d13-bd2a0daff7b9
Host: 000.000.234.90:8082
Accept-Encoding: gzip, deflate, br
Connection: keep-alive