Page 1 of 1

http post/get messages

PostPosted: Tue Mar 15, 2022 9:30 am
by Rutger_Flierman
I want to create a GUI for a SDVoE ControlServer. Sending commands must be HTTP Post and GET messages, can this be done with WD? The API uses a Websocket for notifications, can a connection to the Websocket work in WD (e.g: ws://localhost:80/api)
All best, Rutger

Re: http post/get messages

PostPosted: Sun Mar 20, 2022 5:25 pm
by justyn roy
At the moment, you can do GET requests with the "HTTPRequestToVar()" for these - you'll get a response to a variable.

POST requests aren't supported natively yet but are possible manually if you want to do the work.
It is not something that's native to Widget - it could be done even in something like Putty.
An example of how to accomplish this in Widget V4 can be found here: http://forum.coolux.de/viewtopic.php?f=4&t=3241&p=9545&hilit=aja#p9545

It is can be done more easily now with concatenation instead of needing to use "VAdd"

Re: http post/get messages

PostPosted: Tue Mar 29, 2022 2:30 pm
by Rutger_Flierman
I tried this:
var Command = '{"op" : "leave","subscription_type" : "HDMI","subscription_index" : 0}'
var MSG = ""
MSG = "POST " + "/api/device/000948dd0772 " + "HTTP/1.1 [CR][LF]Connection: keep-alive[CR][LF]"
MSG += "Content-Length: 80" + "[CR][LF] User-Agent: Christie Widget Designer [CR][LF]"
MSG += "Content-Type: application/json [CR][LF][CR][LF]"
MSG += Command
DebugMessage(MSG)

TcpSend(5,MSG)

With Postman I can send this Command and the RX device with MacAdress 000948dd0772 leaves the video stream but from WD no success. Any suggestions?

the HTTPRequestToVar is working :)

Re: http post/get messages

PostPosted: Wed Mar 30, 2022 10:43 am
by Daniel Kaminski
Looks like you are missing a [CR][LF] after the last iine.

MSG += Command + "[CR][LF]"

Re: http post/get messages

PostPosted: Wed Mar 30, 2022 1:40 pm
by Rutger_Flierman
No luck...In the topic from 2018 to control a Datapath the [CR][LF] is also not there in the last line but i added it.

The command line from the debugger looks like this:

POST /api/device/000948dd0772 HTTP/1.1 [CR][LF]Connection: keep-alive[CR][LF]Content-Length: 80[CR][LF] User-Agent: Christie Widget Designer [CR][LF]Content-Type: application/json [CR][LF][CR][LF]{"op" : "leave","subscription_type" : "HDMI","subscription_index" : 0}[CR][LF]

Thanx for the support!

Re: http post/get messages

PostPosted: Fri Apr 01, 2022 10:03 am
by Rutger_Flierman
This is the reply from the control server:
HTTP/1.1 400 Bad Request
Date: Fri, 01 Apr 2022 08:50:01 GMT
Content-Type: application/json
Server: BlueRiver-Control/3.2.0.2
Vary: Origin
Cache-Control: no-store
Connection: close

{
"status" : "ERROR",
"request_id" : null,
"result" : null,
"error" : {
"reason" : "PROTOCOL",
"message" : "Bad request"
}
}

The command line itself is correct because it works when send with Postman or Companion.

thanx, rutger

Re: http post/get messages

PostPosted: Fri Apr 01, 2022 11:03 pm
by justyn roy
The "Content Length" was an issue for me in the past.

I had to change it depending on how many characters I was sending.

Re: http post/get messages

PostPosted: Mon Apr 04, 2022 12:46 pm
by Rutger_Flierman
Thanx Justyn, but I copied the length from Postman (same command) and that should be correct then. I tried values from 60 to 80 (in a for loop 8) ) but no success.

Re: http post/get messages

PostPosted: Fri Apr 08, 2022 3:04 pm
by Martina Protze
We solved the issue by adopting the WD message according to the working examples which we checked in more detail.
As said above, currently WD supports only HTTP GET request via commands. To send HTTP POST requests, the workaround is to send messages with a TCP Client. The messages must include special header information and the command itself.

Rutger solved the issue by setting up a temporary TCP Server (Multi!) to which he sent the Postman/Companion messages from which he knew that they were working. So instead of sending them to the BlueRiver Control Server, he sent them to Widget to have a closer look.
Code: Select all
Please create a TCP Server (Multi!) in the Connection Manager on port 8081 (remember the ID, probably 1). If you right-click it there, you can choose "Test" and it shows incoming messages in a list format, character by character (including CR and LF). If you now create a Node > Input > Connections > TCP Input and set it to the ID from the Connection Manager it shows incoming messages in a more readable way.


He then discovered the following and changed the WD message accordingly and it worked. See below a working example:
- both messages show a space after "POST" which is not included in the initial example above
- The User Agent is not necessary
- Host info is included => I think that is very important
- the Content-Length / number of spaces matter

Thanks everybody for your help on this task!