User Tools

Site Tools


integration_with_other_systems

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
integration_with_other_systems [2019/09/03 14:59] – [Example - connecting to a remote module via its web server] emozolyakintegration_with_other_systems [2020/05/22 11:37] – [Implementing other requests like PUT] emozolyak
Line 4: Line 4:
  
 This function is available since version 2.6.4520. This function is available since version 2.6.4520.
 +
 +===== POST example =====
  
 An example of a program executing an HTTPS request to send data as a file at URL https://demo.com/upload: An example of a program executing an HTTPS request to send data as a file at URL https://demo.com/upload:
Line 32: Line 34:
  
 Note that for SSL certificates correctly function, you need to have an exact local time. If there is a significant deviation of the local clock, https requests may not work. We recommend using time synchronization via NTP server. Note that for SSL certificates correctly function, you need to have an exact local time. If there is a significant deviation of the local clock, https requests may not work. We recommend using time synchronization via NTP server.
 +
 +===== GET example =====
  
 Example of requesting a number in the GET request at URL http://demo.example.com/read-data?param=32 and writing it to the register with id=4356: Example of requesting a number in the GET request at URL http://demo.example.com/read-data?param=32 and writing it to the register with id=4356:
Line 50: Line 54:
 </code> </code>
  
 +===== Implementing other requests like PUT =====
 +
 +To implement other requests, you can use special field in the cURL for the custom methods:
 +
 +<code lua>
 +function main (userId)
 + 
 +    INFO("Doing CURL");
 + 
 +  str = '' 
 +  
 +  c = cURL.easy_init()
 +  c:setopt_url("http://192.168.1.230:8000")
 +  c:setopt_timeout(15)
 +  c:setopt{[cURL.OPT_CUSTOMREQUEST] = "PUT" -- this is custom method
 +  
 +  c:setopt{
 +        [cURL.OPT_POSTFIELDS] = 'Content-type: text/html'
 +  }
 +  c:post({'THIS IS CONTENT OF THE PUT'})
 +  c:perform({writefunction = function(res) str = res end })
 +  c:close()
 +
 +  INFO("CURL done\n" .. str);
 +end
 +</code>
 ===== Example - connecting to a remote module via its web server ===== ===== Example - connecting to a remote module via its web server =====
  
integration_with_other_systems.txt · Last modified: 2024/04/04 10:18 by emozolyak

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki