Home AMX General Discussion

Http commands with username and password

Dear All,
I need to control a system ( ZWave) through IP and http commands. I have already managed to make the command structure ( see below ) but the problem is that I have to get through a username and password for the command to be applied.

send_string dvZWave, "'POST /api/devices/15/action/turnOff HTTP/1.1',13,10"
send_string dvZWave, "'Host: 192.168.10.120',13,10"
send_string dvZWave, "'Connection: keep-alive',13,10"
send_string dvZWave, "13,10"

When sending these commands, a reply says ( on NS diagnostics ) that an unauthorized user is trying to log in.

Below you can see an http fox snap shot while log in the system with u/p admin/admin.
How can I send the username and password with a send_string command before sending the above commands ?






George

Comments

  • sling100sling100 Junior Member Posts: 104
    You need to add an 'authorization' header:

    "Authorization: Basic root:root',13,10"

    The user/password bit needs to be encoded using base 64. There is a function to do it - do a forum search and I'm sure it'll pop up.

    Simon
  • George KrietsepisGeorge Krietsepis Member Posts: 189
    I added the authorization header and the command worked, BUT with a delay of about 2 minutes !!! I really don't know why this happens.
    Once the command is executed - after such a delay - I'm getting the below string:
    SendString 0:0:0 too long 297 truncated to 274
    I have tried many different syntax's with no success.
    Any ideas of why an http command may have such a delay ?

  • viningvining X Member Posts: 4,368
    How is the connection being handled? I would push a button to issue a command that would send a command string to Q which calls IP socket to open. The online event would trigger and that would trigger my code to send my Q'd string to device. With http I don't try to maintain the socket and I don't use any waits or wait untils in my code since everything is event triggered, intially by the button push and then the online event. Sounds to me the delay is in your code, maybe the socket is hanging open and it has to time out before opening again to send..
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    Once the command is executed - after such a delay - I'm getting the below string:
    SendString 0:0:0 too long 297 truncated to 274
    I have tried many different syntax's with no success.

    The SendString message is just a limitation of Netlinx Studio Diagnostic printouts.
    It's no indication that your code is good or bad.
    It just means it can't print that much with 1 SendString 0.
  • ericmedleyericmedley Senior Member - 4000+ posts Posts: 4,177
    I added the authorization header and the command worked, BUT with a delay of about 2 minutes !!! I really don't know why this happens.
    Once the command is executed - after such a delay - I'm getting the below string:
    SendString 0:0:0 too long 297 truncated to 274
    I have tried many different syntax's with no success.
    Any ideas of why an http command may have such a delay ?



    I don't know if the text quoted is accurate or not... But, you don't want to make your IP device 0:0:0. That may just be a typo or whatever. the first two ports (0:1:0 and 0:2:0) are reserved for use by the Netlinx master's internal clockwork. (Technically, I think the published statement is actually just port 0:1:0 - but I've noticed over the years that there seems to be some use of port 2 on occasion. I've never confirmed it with AMX. But I just tend to start at port 3 out of habit)
Sign In or Register to comment.