How to make a Post Http request

Hi,

to connect to a small app which transform an old smartphone into an Ip Camera, I use CamON Live, no problem to use http request Get (I sax it in the example), but to do a poste request, it is not working, can anyone help me, and for the future, is it possible Bill to post an exemple of post method in the documentation for newbies like me :slight_smile: ?
here is an extract of the API :

Control commands

It is possible to control the app remotely by sending POST requests to the URL
http://<ipaddress>:<port>/control
The request’s body should be plain text, specifying one or more commands to execute; the headers should contain Content-Type: text/plain .
Commands can be specified once per row, in the form command=parameters ; rows may be either \n or \r\n terminated.

It is also possible to use a GET request and specify one or more commands in the query string, using the same form command=parameters for each.

Alarm

alarm=play [v:<volume>] [r:<repetitions>]
Activate vibration for the specified duration, if supported by the device.
volume (int) - the sound volume, in percent, default is 100%
repetitions (int) - how many times to repeat the sound, default is 0

What I tried is this :

var response =http.post(“http://xxxx:xxxxx@xx.xx.xx.xx:xxx/control”,“alarm=play [v:20] [r:0]”)

when there was the http client device, it was working, so I known it can work, but how :frowning:?

The default Content-Type header for string data is currently “application/x-www-form-urlencoded”. You’ll have to pass in the options parameter to explicitly set the header value.

var options = { headers: { "Content-Type": "text/plain" } };
var response = http.post("http://xxxx:xxxxx@xx.xx.xx.xx:xxx/control", "alarm=play [v:20] [r:0]", options);

I forget why it’s not using that by default for string content. I’m not sure if that was intentional or not.

Thx, I’m not at home for few days, I’ll try it next weekend ! :slight_smile:

It is working Great ! Thank you !

1 Like