Cannot get local file from device driver

when i do the url from a browser it works fine.. when i try from a device i get the following error

i have tried both http://127.0.0.1/local/file
and the actual ip..

any ideas thanks

@bobbyD

How is it coded? are you using httpGet() or asynchttpGet()?

thanks neither here was old way that worked..

String repositoryText = "http://mail.lgk.com/ecowitt1.css".toURL().getText();

tried just replacing it with

String repositoryText = "http://127.0.0.1/local/ecowitt1.css".toURL().getText();

Google seems to say you would need to use asynhttpGet()

I use asynchttpGet() to call a Google Sheets script to delete data and clean up my logging sheets. I just log the response, but the callback method should get your data as well.

def getDelete(log) {
    sendEvent(name: "lastCleaned", value: log)

    def googleUri = device.currentValue("cleanUri") + "?" + log
    googleUri = googleUri.replace(" ","%20")
    logDebug("Clean Uri is: ${googleUri}")

    def cleanParams = [
		uri: googleUri,
		requestContentType: 'application/json',
		contentType: 'application/json',
		headers: ['CustomHeader':'CustomHeaderValue'],
	]
    asynchttpGet('cleanCallbackMethod', cleanParams, [dataitem1: "datavalue1"])
}
def cleanCallbackMethod(response, data) {
    logDebug("Log Cleaned: ${response}",3)
}

got it to work like this..just strange old one changed to 127.0.0.1/local should have worked the same

// String repositoryText = "http://mail.lgk.com/ecowitt1.css".toURL().getText();

def byte dBytes = downloadHubFile("ecowitt1.css")
def String repositoryText = new String(dBytes)

Ah, handy to know. That's pretty simple :smiley:

I didn't realize you were just pulling a css text file. What I posted would be for using some of the actual endpoints that return json data.

1 Like

stil weird to me why the url works perfectly in a browser going to an external server. or local but with 127.0.0.1/local does not when in a device manager code base.

I think thereโ€™s a port 80 restriction on LocalHost (127.0.0.1).
A guess here: try 8080 or 8081?

3 Likes

This :point_up_2: