Doesn’t seem possible with the HTTP binding unless I’ve missed something?
(And yes the username has the @ symbol in, which adds to the fun )
The above URL would normally return basic xml as below and I’m after the numeric value of “Level”.
You can realize the HTTP request with credentials in your configuration in two ways:
String Test {
http="<[http://username:password@sample.com]"
}
When your username or password contains reserved characters like an @ symbol you should encode the username and password in Base 64 and use a header, where the headers’s value is the base64-encoding of username:password (results in dXNlcm5hbWU6cGFzc3dvcmQ=). There is an online decoder/encoder here.
String Test {
http="<[http://sample.com{Authorization=Basic dXNlcm5hbWU6cGFzc3dvcmQ=}]"
}
I will add this explanation to the HTTP documentation.
I couldn’t get Basic Auth in combination with JSON running directly in an item definition. The only way it worked for me was like described here: Http binding question - cache not working
# configuration of the first cache item
vpm.url=http://192.168.1.XX:80/wizard/public/api/measurements{Authorization=Basic dXNlcjEyMzQ1Njc4OQ==}
vpm.updateInterval=5000
Item
Number meterPT "Gesamtleistung [%.0f W]" <meter> {http="<[vpm:5000:JS(PT.js)]"}
Not working:
Number meterPT1 "Gesamtleistung [%.0f W]" <meter> {http="<[http://192.168.1.XX:80/wizard/public/api/measurements:5000:JS(PT.js){Authorization=Basic dXNlcjEyMzQ1Njc4OQ==}]" }
Number meterPT2 "Gesamtleistung [%.0f W]" <meter> {http="<[http://dXNlcjEyMzQ1Njc4OQ==@192.168.1.XX:80/wizard/public/api/measurements:5000:JS(PT.js)]" }
Of course credentials above are not the real ones.
Probably it would be helpful for other noobs to put a full example with BasicAuth in the http Binding docu (http://docs.openhab.org/addons/bindings/http1/readme.html)
At least for me it wasn’t clear where to put the credentials.
I probably got the simular issue. The server I am trying to request is ccu.sh, documentation provides example of request. h ttps://ccu.sh:8080/data.cgx?cmd={“Command”:“GetStateAndEvents”}
It contains json format data. Could you help with the proper binding or item definition that incorporates basic authentification?