Android Question "Authorization" HTTP request header with Domoticz

krissam

Member
Licensed User
Longtime User
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 :
B4X:
httpjob.PutString("http://domoticz-ip:port/json.htm?type=command&param=switchlight&idx=19&switchcmd=On", "" )

But I need basic authorization.
Domoticz documentation :

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
 

chefe82

Member
Licensed User
Longtime User
check this

B4X:
connection.Initialize("Domoticz", Me)
connection.PostString("http://www.xxx.fr:8080", "")
connection.Username = Your Username
connection.Password = Your Password
 
Upvote 0

krissam

Member
Licensed User
Longtime User
Thanks chefe82,

Why trying to make things so complicated when they can be so simple !

Now when I'll return from my office, I'll be able to open my house gate!!!

Regards
 
Upvote 0

krissam

Member
Licensed User
Longtime User
Now my application is working but I get this error few minutes after lauching it :
ResponseError. Reason: java.io.IOException: unexpected end of stream on okhttp3.Address@a387b295, Response:
JobName = Domoticz, Success = false
Error: java.io.IOException: unexpected end of stream on okhttp3.Address@a387b295
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…