Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Send data via HTTP POST request


Question

Posted

I've got a code that is sending the data via GET request:

 

-- performs a GET method on given uri, takes function as a parameter in case of success
getMethod = function(uri, success)
 
  local http = net.HTTPClient() -- creating object for performing HTTP call
 
    http:request(uri, {
        options = {
          method = 'GET'
        },
 
        success = success, -- function executed in a case of successful connection
 
        error = function(err) -- function executed in a case of connection error
          print('error' .. err)
        end
  })
end
 
The "uri" is a normal link which looks like =

Please login or register to see this link.

 
And that works, but i need to send data via POST request. When i change the method to 'POST', it connect to server, but it doesn't send data. I don't exactly know how to write this data.
 
Would be really grateful for any help.

5 answers to this question

Recommended Posts

  • 0
Posted

You have to send the data in the options part like:

Please login or register to see this code.

  • 0
  • Inquirer
  • Posted

    Still can't send data....how do you describe variable payload? Something like this? payload = "action=create&description=myData&moreDescription=moreData

    • 0
    Posted

    What do you need to post?

     

    In the example above the payload would be something like: data1=vari1&data2=vari2

    • 0
    Posted

    Hi,

     

    I have the following code and it works perfectly in a scene:

    Please login or register to see this code.

    I want to insert a globalVariable value in the "data" set.  For example, I want to send my current switch energy consumption.

     

    Any suggestions?

    • 0
    Posted

    Is this what you intend to do?

     

    Please login or register to see this attachment.

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...