POST issue


(Steve Bratt) #1

im getting a strange response from a lan connected device when using smartthings which isnt the same when scripting in go. can anyone tell me why i might get this error?

12:37:12 PM: error java.lang.NullPointerException: Cannot get property ‘Content-Type’ on null object @ line 187

debug Parsing ‘index:17, mac:B8AC6FE03719, ip:C0A80032, port:0050, requestId:21fea4e7-dca4-4389-9d28-42bc9b3e7411, body:PCFET0NUWVBFIGh0bWwgUFVCTElDICItLy9XM0MvL0RURCBYSFRNTCAxLjAgVHJhbnNpdGlvbmFsLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL1RSL3hodG1sMS9EVEQveGh0bWwxLXRyYW5zaXRpb25hbC5kdGQiPgo8aHRtbCB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94aHRtbCI+CjxoZWFkPgo8bWV0YSBodHRwLWVxdWl2PSJDb250ZW50LVR5cGUiIGNvbnRlbnQ9InRleHQvaHRtbDsgY2hhcnNldD11dGYtOCI+Cjx0aXRsZT5ERUxMIFMzMDB3IFdlYiBNYW5hZ2VtZW50PC90aXRsZT4KPGxpbmsgaHJlZj0iL2ZvbnRfc3R5bGUuY3NzIiByZWw9InN0eWxlc2hlZXQiIHR5cGU9InRleHQvY3NzIj4KPC9oZWFkPgo8Ym9keT48c2NyaXB0PgphbGVydCgiV3JvbmcgUGFzc3dvcmQhIFBsZWFzZSB0eXBlIHlvdXIgcGFzc3dvcmQgYWdhaW4uIik7CmxvY2F0aW9uLnJlcGxhY2UoIi9jZ2ktYmluL2xvZ2luX2FkbWluLmNnaT9sYW5nPTAiKQo8L3NjcmlwdD4KPG5vc2NyaXB0PgpQYXNzd29yZCBlcnJvci4KPC9ub3NjcmlwdD4KPC9ib2R5PjwvaHRtbD4K’

debug Result2 is OK

debug POST /cgi-bin/login_admin.cgi?lang=0 HTTP/1.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
HOST: 192.168.0.50:80
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
Cache-Control: max-age=0
Connection: keep-alive
Content-Length: 31
Content-Type: application/x-www-form-urlencoded
Origin: http://192.168.0.50:80
Referer: http://192.168.0.50:80/cgi-bin/login_admin.cgi?lang=0
Upgrade-Insecure-Requests: 1

here is the code

def on() {
log.debug("Executing hubAction on " + getHostAddress())

def uri = “/cgi-bin/login_admin.cgi?lang=0"
def body = [user:“admin”, password:”", Login:“login”]
def headers = [:]
headers.put(“HOST”, “192.168.0.50:80”)
//headers.put(“Content-Type”, “text/html”)
headers.put(“Accept”, “text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8”)
headers.put(“Accept-Encoding”, “gzip, deflate”)
headers.put(“Accept-Language”, “en-US,en;q=0.8”)
headers.put(“Cache-Control”, “max-age=0”)
headers.put(“Connection”, “keep-alive”)
headers.put(“Content-Length”, “31”)
headers.put(“Content-Type”, “application/x-www-form-urlencoded”)
headers.put(“Origin”, “http://192.168.0.50:80”)
headers.put(“Referer”, “http://192.168.0.50:80/cgi-bin/login_admin.cgi?lang=0”)
headers.put(“Upgrade-Insecure-Requests”, “1”)
headers.put(“User-Agent”, “Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36”)
log.debug “Headers are ${headers}”

def result = new physicalgraph.device.HubAction(
method: “POST”,
path: uri,
headers: headers,
body: body
)

log.debug result
def result2 = sendHubCommand(result)
log.debug “Result2 is ${result2}”
}

def parse(description) {
log.debug (“Parsing ‘${description}’”)
def msg = parseLanMessage(description) //this is line 187
log.debug “Returned Message ${msg}”
}


(Steve Bratt) #2

decoding the response you can see it is responding with data

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>DELL S300w Web Management</title>
<link href="/font_style.css" rel="stylesheet" type="text/css">
</head>
<body><script>
alert("Wrong Password! Please type your password again.");
location.replace("/cgi-bin/login_admin.cgi?lang=0")
</script>
<noscript>
Password error.
</noscript>
</body></html>