HTTP Get - Using HTTPS - Should work in RM?

Does anyone have a HTTP Get that points to a HTTPS address? Does it work correctly?

I have a couple that I am trying to run, but though they work in Safari, they do not seem to run in a rule in RM. (Testing as the only action in the rule, ran manually, confirmed run in the logs.)

It seems to be working. Make sure your cert is trusted, or it won't work

1 Like

Thanks! Will check that. I would have expected my browser to complain about that if it wasnā€™t trusted, but have no idea reallyā€¦. :slight_smile:

Update: I just confirmed that the certificate is validā€¦

What I find odd is that it works in Safari, just not in RMā€¦

Are you trying to retrieve the payload or what's the reason you are calling the URL?

i do https calls in one of my drivers and it works fine. i know you specifically asked about RM but i would imagine they both ultimately use the same libraries/methods in the backend. don't know if that helps you at all Sebastien...i've never tried it in RM

1 Like

I need to share the status of a sensor with a neighbour. He provided me with a HTTP Get URL that he will use to receive a notification.

Unfortunately, the URL works from a browser, but for some reason, it doesnā€™t from RM.

Does RM give you a response status back?

Not as far as I can see, though I am so unfamiliar with HTTP Get that I might just not know where to lookā€¦. Nothing in the logs, except that it ran.

Might be worth writing a quick driver to send it just to see the response the hub is getting (although at that point you could just access the data from the driver...)

Thatā€™s a good ideaā€¦ never wrote a driver before thoughā€¦

1 Like

I've created the test page that should help you see if RM can call an HTTPS URL.
If you can call
https://public.theigor.net/hub_test/index.php?test=my_hub_test, it will create a file https://public.theigor.net/hub_test/my_hub_test.txt with date and time.

my_hub_test can be anything you want in the URL and it will be available at https://public.theigor.net/hub_test/{your test name}.txt
Let me know if this works for you.

2 Likes

Here is the result of my test:


Screenshot from 2021-05-21 08-50-56

Also, you can use this site to test the cert. There is a good chance that the chain is not installed properly but it seems you are using Cloudflair which should be configured correctly..
https://www.ssllabs.com/ssltest/

1 Like

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

Thanks @igorkuz! I ran a test and it worked perfectly.

The address I am trying to "Get" has an "&" in it. other than that, the characters are the same as what you provided. I wonder if that makes a difference...

Very nice! Thank you for this. It eliminates RM as the culprit as I unfortunately get the same result... Continuing to try to figure it out...

May need to run it through a urlEncode to remove any ā€œillegalā€ characters.

1 Like

The "&" shouldn't meter it's a valid url character. If you would like, you can PM me the URL and I can try replicating it for you to test on my server. If it works, then the problem would be on the server side. You can also talk to the person that gave you the url and ask him/her to check the app or http server logs, it should help you ping-point the issue.

2 Likes

Will do! Thanks!

I will trobleshoot it for you when I get home from work in couple hours. URL looks good and it should be working. The only thing I can think off is that Cloudflair app firewall is filtering your requests, I will be able to tell you when I do some tests.

Much appreciated!