This should work for a test:
HTTP Get Tester
/*
* HTTP Get Test
*
* Licensed Virtual the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
* Change History:
*
* Date Who What
* ---- --- ----
* 2021-05-21 thebearmay Original version 0.1.0
*
*/
static String version() { return '0.1.0' }
metadata {
definition (
name: "HttpGet Tester",
namespace: "thebearmay",
author: "Jean P. May, Jr.",
importUrl:""
) {
capability "Actuator"
capability "Configuration"
capability "PresenceSensor"
attribute "getReturn", "string"
command "sendGet", [[name:"ipAddress*", type:"STRING", description:"Site to send Get"], [name:"path*", type:"STRING", description:"Path for Get"]]
}
}
preferences {
input("debugEnable", "bool", title: "Enable debug logging?")
input("security", "bool", title: "Hub Security Enabled", defaultValue: false, submitOnChange: true)
if (security) {
input("username", "string", title: "Hub Security Username", required: false)
input("password", "password", title: "Hub Security Password", required: false)
}
}
def installed() {
log.trace "installed()"
}
def configure() {
if(debugEnable) log.debug "configure()"
updateAttr("getReturn"," ")
}
def updateAttr(aKey, aValue){
sendEvent(name:aKey, value:aValue)
}
def updateAttr(aKey, aValue, aUnit){
sendEvent(name:aKey, value:aValue, unit:aUnit)
}
def initialize(){
}
def sendGet(ipAddress, path){
if(security) {
httpPost(
[
uri: "http://127.0.0.1:8080",
path: "/login",
query: [ loginRedirect: "/" ],
body: [
username: username,
password: password,
submit: "Login"
]
]
) { resp -> cookie = resp?.headers?.'Set-Cookie'?.split(';')?.getAt(0) }
}
params = [
uri: ipAddress,
path: path,
headers: [ "Cookie": cookie ]
]
asynchttpGet("sendGetHandler", params)
}
def sendGetHandler(resp, data) {
def errFlag = 0
try {
if(resp.getStatus() == 200 || resp.getStatus() == 207) {
strWork = resp.data.toString()
if(debugEnable) log.debug strWork
sendEvent(name:"getReturn",value:strWork)
}
} catch(Exception ex) {
}
}
def updated(){
log.trace "updated()"
if(debugEnable) runIn(1800,logsOff)
}
void logsOff(){
device.updateSetting("debugEnable",[value:"false",type:"bool"])
}
Need to spilt URI from the path, so using
https:/public.theigor.net/hub_test/my_hub_test.txt
URI = https://public.theigor.net
Path= /hub_test/my_hub_test.txt