POST used to work in hubAction but doesn't anymore

Has there been a change that I am not aware of ? This used to work.

It works if username/password isn't set on the device

def sendSwitchCommand(action) {
    if (txtEnable) "Calling ${action} with ${body}"
	def path = path
	def body = body
	def headers = [:]
    if (username != null) {
        headers.put("HOST", "${username}:${password}@${ip}")
    } else {
        headers.put("HOST", "${ip}")

    headers.put("Content-Type", "application/x-www-form-urlencoded")
    runIn(2, refresh)

	try {
		def hubAction = new hubitat.device.HubAction(
			method: "POST",
			path: action,
			body: body,
			headers: headers
		logDebug hubAction
		return hubAction
	catch (Exception e) {
        logDebug "sendSwitchCommand hit exception ${e} on ${hubAction}"

Logs show

dev:372019-12-05 03:07:03.012 pm debug POST /color/0?turn=on HTTP/1.1
Accept: */*
User-Agent: Linux UPnP/1.0 Hubitat
Content-Type: application/x-www-form-urlencoded
Content-Length: 0

There was a change to โ€˜postโ€™ but I believe with the latest hotfix it has been reverted.

Not sure if it might have been just RM


Seems that fix was for RM only.

Still broken in hubaction code. @bravenel

1 Like

There's been no change to this in any recent release. Problem was RM specific.

hmm it used to work... I haven't changed any of this code in a long time and it worked when I first coded the driver.

Do you see anything in that snippet that would stop it from working?

You aren't encoding the username and password in the URL, so if you're using any special character, that is a likely failure point. That's quite possibly not the issue here, but it's definitely something I'd suggest looking at in the future. Your catch will also throw its own exception because hubAction is not defined in its scope--definitely not the problem here, but something I'd fix. :slight_smile:

To really test this, I'd suggest creating a smaller test case for yourself, perhaps a minimal driver where you forget the if and just literally set the value of this item, something like:

headers.put("HOST", "myliteralusername:myliteralpassword@theliteralIPaddress")

and see if that works, perhaps with and without the username and password.

If you believe it's a platform change causing the problem, you could also downgrade to 2.1.7 from the port 8081 diagnostic UI (be careful if you use Thermostat Manager, as noted in the release notes). If it doesn't work there either, you've ruled something out. :slight_smile: If it does and breaks when you upgrade, perhaps you've discovered something.

Did not work. Only works WithOUT the credentials.

I tried multiple ways and it simply does not work and I have no idea what version it changed in but I know it wasn't working in the last version either.

@bravenel please test on your side because it simply is not working on mine.

Finally got it !! Had to rewrite the whole routine...

Fixed with

def params = [uri: "http://${username}:${password}@${ip}/${action}"]
try {
httpPost(params) {
    resp -> resp.headers.each {
    logDebug "Response: ${} : ${it.value}"
} // End try
} catch (e) {
    log.error "something went wrong: $e"