HTTP Request

Discussions about RaZberry - Z-Wave board for Raspberry computer
darkyat
Posts: 11
Joined: 17 Jul 2014 22:41

Re: HTTP Request

Post by darkyat »

For me it looks like the "User Authentication" is not working as expected.

EDIT:
After a while of "try and error" I discovered that only the password field matters. The header is only set to the base64 hash of the "password" inside the "auth" section. The "login" is completly ignored...

Initial Toughts
If I set:

Code: Select all

                auth: {
                        login: "xyz",
                        password: ""
                },
it won't show up on the other end:

Code: Select all

POST / HTTP/1.1
User-Agent: XMLHttpRequest
Host: localhost:11122
Accept: */*
Content-Length: 41
Content-Type: application/x-www-form-urlencoded

type=note&title=Motion detected&body=Test
If I set username and password the header will be set but not base64 encoded. It's encoded to something "strange".

Code: Select all

POST / HTTP/1.1
Authorization: Basic eHl6Og==
User-Agent: XMLHttpRequest
Host: localhost:11122
Accept: */*
Content-Length: 41
Content-Type: application/x-www-form-urlencoded

type=note&title=Motion detected&body=Test
If I'm trying to base64 encode it myself and attach it as header it will be "encoded" and is therefore unusable as well.

Code: Select all

                headers : {
                        "Authorization" : "Basic <base64string>"
                },

Code: Select all

POST / HTTP/1.1
User-Agent: XMLHttpRequest
Host: localhost:11122
Accept: */*
Authorization: Basic%20<base64string>
Content-Length: 41
Content-Type: application/x-www-form-urlencoded

type=note&title=Motion detected&body=Test
Should the "auth" be working? Unfortunately it isn't for me. :(
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: HTTP Request

Post by pofs »

Yes, auth parameter is ignored if either login or password is not present.
darkyat wrote:but not base64 encoded. It's encoded to something "strange".

Code: Select all

POST / HTTP/1.1
Authorization: Basic eHl6Og==
User-Agent: XMLHttpRequest
Host: localhost:11122
Accept: */*
Content-Length: 41
Content-Type: application/x-www-form-urlencoded

type=note&title=Motion detected&body=Test
Why do you think it is not base64?

Code: Select all

MacBook-Air:~ pieceofsummer$ echo eHl6Og== | base64 -D
xyz:
So it is base64-encoded login "xyz" with divider and empty password.

But yes, there was a bug with auth. It is already fixed, but not sure when it will be released.
For now, specify "username" in login and "username:password" in password parameter.
raZcherry
Posts: 11
Joined: 24 Jun 2014 01:14

Re: HTTP Request

Post by raZcherry »

raZcherry wrote:
It seems to be that on a post request the headers with "Content-Type" : "application/json" will not correctly encoded. The same for "text/xml" . %2F in picture two is the URL-encoding value for /.
Hi All,
I just want to share my workaround for the encoding issue on Z-Way. I am using the internal "system" command of z-way and calling a script. The bash script is calling curl, which creates http header and body for me.
In z-way it looks like:

Code: Select all

 var output = system("/opt/z-way-server/automation/myscript.sh " + firstParam + " " + secondParam);
Bash script:

Code: Select all

#!/bin/bash 
curl -sS -X POST -H "Content-Type:application/json" -d $1 $2 
Next, you must edit the .syscommands under your automation folder with the full path of your script, otherwise z-way is preventing the execution.

Code: Select all

/opt/z-way-server/automation/myscript.sh
In variable output, I got a object (an array) , which contains two elements. First element is always 0 and the second element is the output of the bash script.
Does anybody know the meaning of the first element? It could be an exit status. I returned an exist status =! 0 in the bash script, but first element is always 0. It could be also the exit status of the system command of Z-Way.

Maybe someone has also a better workaround/idea for this.
The best would be fixing the encoding issue ;)
Using: Z-Way v2.0.1-rc11 on Raspberry Pi
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: HTTP Request

Post by pofs »

Just to follow up: all the mentioned http bugs were fixed in 1.7.2
Post Reply