Question about httpPost


(Eric) #1

When I do an httpPost to a local address, I am assuming it doesn’t use my local network and I really need to address my devices with the IP given to me by the ISP and open ports on my router. That right?

Also, when I do this I am attempting to connect to my Roku, which I can do locally or using my ISP up using

curl -d ‘’ http://(ip):8060/

However when doing this in a smart app using http post I get a Forbidden response. Also, I have 9251 forwarded to 8060.

private sendKeyPressToLocalRoku(ip, keyPress, body = “”) {
def params = [
method: “POST”,
uri: “http://ip:9251/keypress/${keyPress}”,
contentType: “application/x-www-form-urlencoded”,
requestContentType:“application/x-www-form-urlencoded”,
headers: [
""
],
body: body
]

try {
	httpPost(params) { resp ->
   }
    
    return true
} catch(Exception e) {
    log(e, "ERROR")
    return false
}

}


(www.rboyapps.com - Make your home your butler!) #2

Use hubAction, that works on the hub


( I hate Mondays) #3

Correct, httpPost is executed in the cloud, you need the public IP and port forwarding. HubAction on the other hand uses the hub to connect, so you can use the internal IP and no port forwarding needed. However, it cannot yet do HTTPS requests.


(Eric) #4

Ok, so the curl that works is…

curl -d '' http://192.168.1.20:8060/keypress/home

and here is my SmartApp code which does not…

`private sendKeyPressToRoku() {

def result = new physicalgraph.device.HubAction(
    method: "POST",
    path: "/keypress/home",
    headers: [
        HOST: "192.168.1.20:8060"
    ]
)

log("Result = ${result}.", "DEBUG")

return result

}`

The value of result when done is…

POST /keypress/home HTTP/1.1 Accept: */* User-Agent: Linux UPnP/1.0 SmartThings HOST: 192.168.1.20:8060


(Michael) #5

IPs have to be in hex value. See this old thread that helped me in the past:


(Eric) #6

This isn’t a device that is “paired” to ST. It is just a roku on my local network. I tried hex, still didn’t work.


( I hate Mondays) #7

If you go to my github, look at the HomeCloudHub app, it uses HubAction, including SSDP discovery. You need to subscribe to location to get LAN packets.


(Eric) #8

Thanks guys, I kept following the thread that @ritchierich posted and the code in there from @geko worked.