MATLAB Answers

How can I best receive data from a web hook into Matlab?

35 views (last 30 days)
Brian Greer
Brian Greer on 12 Apr 2021 at 2:22
Commented: Walter Roberson on 15 Apr 2021 at 22:02
There is website that can send text data via a webhook. I would like to process that data in Matlab. How can I best receive data from a webhook into Matlab?
Thank you VERY much.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Apr 2021 at 2:39
The URL for the webhook could be connected to a webserver on your host that accepted the request (such as with PHP or ASP), constructed whatever data was needed, and invoked MATLAB (possibly through a the Automation Server API)
Or the URL for the webhook could be configure for a port that you have a MATLAB session directly listening on, such as by using tcpserver() with you handling the parsing and action in MATLAB. There is also a File Exchange contribution for handling TCP, UDP, and IP services.
Walter Roberson
Walter Roberson on 15 Apr 2021 at 22:02
There are some protocols such as SMTP where it is normal for the server to reply with a greeting upon connection. It is not normal for HTTP though: for HTTP the client makes the connection and then immediately sends the command on the first line, and then sends optional headers on the second and following lines, ending with an empty line. The server then replies first with a header block, that might look something like
HTTP/1.1 200 OK
X-robots-tag: noindex,nofollow
Content-type: text/html; charset=UTF-8
Content-Length: 8595
Date: Thu, 15 Apr 2021 06:49:56 GMT
Server: Thanks For All The Fish Server
and then an empty line and then with HTML.
If you choose to implement directly in MATLAB, your code will be responsible for reading the command from the client, taking the appropriate action, and then replying with a header block, then an empty line, and then with an HTML block, and then closing the connection. As that can all be a bit of a nuisance, it is common to instead use a webserver program such as PHP or ASP. Or these days, probably python.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by