Hello,
I'm trying to developp a small B4A application to open and close my house gate.
To do this I just need to send to my domoticz server :
But I need basic authorization.
Domoticz documentation :
Here is the piece of code I' testing and It doesn't work : "400 Bad Request"
If somebody can help me.
Best regards
I'm trying to developp a small B4A application to open and close my house gate.
To do this I just need to send to my domoticz server :
B4X:
httpjob.PutString("http://domoticz-ip:port/json.htm?type=command¶m=switchlight&idx=19&switchcmd=On", "" )
But I need basic authorization.
Domoticz documentation :
When using some method other than a browser to connect to Domoticz it may be necessary to do Authorization differently. Authorization over HTTP is done by setting the "Authorization" HTTP request header when sending the request to Domoticz. The value of this header is a base64 encoded string of the username and password. When connecting to Domoticz using a browser and the URL method above the browser sets the appropriate header. When creating your own app or script this is not always done for you.
This results in a header in the following format:
- First the username and password are combined into one string "usernameassword"
- This string is encoded using the RFC2045-MIME version of base64
- The authorization method and a space i.e. "Basic " is then put before the encoded string.
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Here is the piece of code I' testing and It doesn't work : "400 Bad Request"
B4X:
Dim connection As HttpJob
Dim userPwd As String = "user:password"
Dim su As StringUtils
Dim byt() As Byte = userPwd.GetBytes("UTF8")
Dim suUserPwd As String = su.EncodeBase64(byt)
connection.Initialize("Domoticz", Me)
connection.PostString("http://www.xxx.fr:8080", "")
connection.GetRequest.SetHeader("Authorization:","Basic "&suUserPwd)
If somebody can help me.
Best regards