diff --git a/nest.devicetype.groovy b/nest.devicetype.groovy index ce5c9a8..54ac84f 100644 --- a/nest.devicetype.groovy +++ b/nest.devicetype.groovy @@ -327,12 +327,23 @@ def doRequest(uri, args, type, success) { ], body: args ] + + def postRequest = { response -> + if (response.getStatus() == 302) { + def locations = response.getHeaders("Location") + def location = locations[0].getValue() + log.debug "redirecting to ${location}" + doRequest(location, args, type, success) + } else { + success.call(response) + } + } try { if(type == 'post') { - httpPostJson(params, success) + httpPostJson(params, postRequest) } else if (type == 'get') { - httpGet(params, success) + httpGet(params, postRequest) } } catch (Throwable e) { login() @@ -370,4 +381,4 @@ def cToF(temp) { def fToC(temp) { return (temp - 32) / 1.8 -} +} \ No newline at end of file