Agent to HTTP:POST a simple url (no JSON headers/body)

Working on a simple push button that has the agent post a “http post” request. If I copy/paste the following url into a browser, the switch I am trying to control comes on. I would like to do the same with the imp push button.


The pushbutton works, the agent acknowledges the press, but I have no idea on how to “http:post” without all of the json headers/body/etc required. I can use Chrome with the url above and the switch comes on. I can also use Tasker/Android to http:post the url and it works as well.

I tried in the code below to follow this link and load a control id and command parameter as a body string, but it does not work.

Any ideas on what I’m missing?

Agent Code:
function store(state2) {
server.log(“Button Pressed”);

device.on(“Pressed on Device”, store);

function HttpPostWrapper() {
local url = ""
local string = {“control_id”: 192, “command_param”: “on”};
local headers = {“Content-Type”: “application/json”};
local req =, headers, http.jsonencode(string));
local response = req.sendsync();
return response;

Device Code:
pb <- hardware.pin1;
function pbpress() {
local state2 =;
if (state2 == 1) {
} else {

function toggleurl() {
agent.send(“Pressed on Device”,0);

You should just be able to do:“”, 192, “on”), {}, “”).sendsync();

  • you’re just adding to the URL there, so there’s no need to send stuff in the body.

So…first thank you.

Fortunately, the above does work but only if I put the raw IP address in (address:port, XX.XXX.XX.XX:YYYY).

Unfortunately, when I put the DNS address in, it fails (I use DNS addresses to keep the address constant). I can confirm the DNS address works/port is open as the browser turns the switch on.

Is there something I need to do to allow using a DNS address in a http:post?

Thanks for the help.

No, DNS addresses should work fine - very very few people use IP addresses.

Could you send me (by PM if required) the DNS address, your agent ID, and a UTC timestamp of when you saw an issue? I can look in the logs and see what appears to be happening.