<div dir="ltr"><div>This is a snippet of a LUA script I'm using:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">...</font></div><div><div><font face="monospace, monospace">require "ltn12"</font></div></div><div><div><font face="monospace, monospace">conn = require "socket.http"</font></div></div><div><div><font face="monospace, monospace">conn.TIMEOUT = 2</font></div></div><div><div><font face="monospace, monospace"><br></font></div></div><div><div><font face="monospace, monospace">function sendRequest()</font></div></div><div><div><font face="monospace, monospace"> local path = "<a href="http://example.com/">http://example.com/</a>"</font></div></div><div><div><font face="monospace, monospace"> local payload = "SOME_JSON"</font></div></div><div><div><font face="monospace, monospace"> local response_body = { }</font></div></div><div><div><font face="monospace, monospace"><br></font></div></div><div><div><font face="monospace, monospace"> local res, code, response_headers, status = conn.request</font></div></div><div><div><font face="monospace, monospace"> {</font></div></div><div><div><font face="monospace, monospace"> url = path,</font></div></div><div><div><font face="monospace, monospace"> method = "POST",</font></div></div><div><div><font face="monospace, monospace"> headers =</font></div></div><div><div><font face="monospace, monospace"> {</font></div></div><div><div><font face="monospace, monospace"> ["Authorization"] = "Basic SOMETHING",</font></div></div><div><div><font face="monospace, monospace"> ["Content-Type"] = "application/json",</font></div></div><div><div><font face="monospace, monospace"> ["Content-Length"] = payload:len()</font></div></div><div><div><font face="monospace, monospace"> },</font></div></div><div><div><font face="monospace, monospace"> source = ltn12.source.string(payload),</font></div></div><div><div><font face="monospace, monospace"> sink = ltn12.sink.table(response_body)</font></div></div><div><div><font face="monospace, monospace"> }</font></div></div><div><div><font face="monospace, monospace"> session:setVariable("my_http_res, res)</font></div></div><div><div><font face="monospace, monospace"> session:setVariable("<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">my_</span>http_code", code)</font></div></div><div><div><span style="font-family:monospace,monospace"> session:setVariable("</span><span style="font-family:monospace,monospace">my_</span><span style="font-family:monospace,monospace">http_status", status)</span><br></div></div><div><div><font face="monospace, monospace">end</font></div></div><div><div><font face="monospace, monospace"><br></font></div></div><div><div><font face="monospace, monospace">sendRequest()</font></div></div><div><font face="monospace, monospace">...</font></div></blockquote><div><br></div><div><br></div><div>In my case, I have to do a <b>POST</b> of an "<b>application/json</b>" with <b>Basic auth</b>.</div><div><br></div><div>I found this pretty helpful:</div><div><br></div><div><a href="http://w3.impa.br/~diego/software/luasocket/http.html">http://w3.impa.br/~diego/software/luasocket/http.html</a><br></div><div><br></div><div><br></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">lol I also remember going through a headache to get this "simple" thing working..</span><br></div><div><br></div><div><br></div><div>Hope it helps!</div><div><br></div><div>Joel.</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 19, 2018 at 10:57 PM, Jose David Jurado Alonso <span dir="ltr"><<a href="mailto:josedavid@zennio.com" target="_blank">josedavid@zennio.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><pre class="m_7703539112658186186gmail-tw-data-text m_7703539112658186186gmail-tw-ta m_7703539112658186186gmail-tw-text-small" id="m_7703539112658186186gmail-tw-target-text" style="height:144px" dir="ltr"><span lang="en">Thank you very much David, if you find the script it would be a great help.
I have been on vacation and I have not been able to try much more in this time.</span></pre><div><div class="h5"><div class="gmail_extra"><div><div class="m_7703539112658186186gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><p style="font-size:12.8px"><span style="font-size:small">2018-08-03 20:07 GMT+02:00 David Villasmil </span><span dir="ltr" style="font-size:small"><<a href="mailto:david.villasmil.work@gmail.com" target="_blank">david.villasmil.work@gmail.<wbr>com</a>></span><span style="font-size:small">:</span><br></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Oh this took me some time to figure out, i'll dig up ny script and share it with you.</p>
<br><div class="gmail_quote"><div><div class="m_7703539112658186186h5"><div dir="ltr">On Fri, Aug 3, 2018, 13:16 Jose David Jurado Alonso <<a href="mailto:josedavid@zennio.com" target="_blank">josedavid@zennio.com</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_7703539112658186186h5"><div dir="ltr">Hi,<div><br>I have tried to make a HTTP POST request from LUA script but it does not work correctly in any way.<div><div><br></div><div>This is an example of the errors that I have obtained:
<div><br></div></div></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><div><div><div><font face="times new roman, serif">09802b39-524f-4011-ada7-418e6a<wbr>870248 2018-08-03 12:23:07.981581 [ERR] mod_lua.cpp:203 error loading module socket.core from file /usr/local/lib/lua/5.1/socket/<wbr>core.so:</font></div></div></div></div></div><div><div><div><div><font face="times new roman, serif">09802b39-524f-4011-ada7-418e6a<wbr>870248 <span style="white-space:pre-wrap"> </span>/usr/local/lib/lua/5.1/socket/<wbr>core.so: undefined symbol: lua_pcall</font></div></div></div></div><div><div><div><div><font face="times new roman, serif">09802b39-524f-4011-ada7-418e6a<wbr>870248 stack traceback:</font></div></div></div></div><div><div><div><div><font face="times new roman, serif">09802b39-524f-4011-ada7-418e6a<wbr>870248 <span style="white-space:pre-wrap"> </span>[C]: in ?</font></div></div></div></div><div><div><div><div><font face="times new roman, serif">09802b39-524f-4011-ada7-418e6a<wbr>870248 <span style="white-space:pre-wrap"> </span>[C]: in function require</font></div></div></div></div><div><div><div><div><font face="times new roman, serif">09802b39-524f-4011-ada7-418e6a<wbr>870248 <span style="white-space:pre-wrap"> </span>/usr/local/share/lua/5.1/socke<wbr>t.lua:12: in main chunk</font></div></div></div></div><div><div><div><div><font face="times new roman, serif">09802b39-524f-4011-ada7-418e6a<wbr>870248 <span style="white-space:pre-wrap"> </span>[C]: in function require</font></div></div></div></div><div><div><div><div><font face="times new roman, serif">09802b39-524f-4011-ada7-418e6a<wbr>870248 <span style="white-space:pre-wrap"> </span>/usr/local/share/lua/5.1/socke<wbr>t/http.lua:10: in main chunk</font></div></div></div></div><div><div><div><div><font face="times new roman, serif">09802b39-524f-4011-ada7-418e6a<wbr>870248 <span style="white-space:pre-wrap"> </span>[C]: in function require</font></div></div></div></div><div><div><div><div><font face="times new roman, serif">09802b39-524f-4011-ada7-418e6a<wbr>870248 <span style="white-space:pre-wrap"> </span>/usr/share/freeswitch/scripts/<wbr>test.lua:3: in main chunk</font></div></div></div></div></blockquote><div><div><div><br></div></div><div><br></div><div>The lua script is:</div><div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><div><font face="times new roman, serif">local http = require "socket.http";</font></div></div></div><div><div><div><font face="times new roman, serif"><br></font></div></div></div><div><div><div><font face="times new roman, serif">local req_url = "<a href="http://localhost/" target="_blank">http://localhost/</a>"</font></div></div></div><div><div><div><font face="times new roman, serif"><br></font></div></div></div><div><div><div><font face="times new roman, serif">http.request{</font></div></div></div><div><div><div><font face="times new roman, serif"> url = req_url,</font></div></div></div><div><div><div><font face="times new roman, serif"> method = "POST"</font></div></div></div><div><div><div><font face="times new roman, serif">}</font></div></div></div></blockquote><div><div><br></div><div><br></div><div>I tried several tutorials and several configurations:</div><div><br></div><div><ul><li><a href="https://freeswitch.org/confluence/display/FREESWITCH/Installing+LuaSocket" target="_blank">https://freeswitch.org/conflue<wbr>nce/display/FREESWITCH/Install<wbr>ing+LuaSocket</a><br></li><li><a href="https://freeswitch.org/confluence/display/FREESWITCH/Third+Party+Libraries" target="_blank">https://freeswitch.org/conflue<wbr>nce/display/FREESWITCH/Third+<wbr>Party+Libraries</a> with <a href="https://luarocks.org/modules/jakeg/lua-requests" target="_blank"> https://luarocks.org/mo<wbr>dules/jakeg/lua-requests</a><br></li></ul><div>And some other things that I do not remember but always fail for some "undefined symbol".</div></div></div><div><br></div><div>Any ideas? Thanks!</div><div><br></div><div>José D.</div></div></div></div>
______________________________<wbr>______________________________<wbr>_____________<br>
Professional FreeSWITCH Services<br>
<a href="mailto:sales@freeswitch.com" target="_blank">sales@freeswitch.com</a><br>
<a href="https://freeswitch.com" rel="noreferrer" target="_blank">https://freeswitch.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="https://freeswitch.com/oss" rel="noreferrer" target="_blank">https://freeswitch.com/oss</a><br>
<a href="https://freeswitch.org/confluence" rel="noreferrer" target="_blank">https://freeswitch.org/conflue<wbr>nce</a><br>
<a href="https://cluecon.com" rel="noreferrer" target="_blank">https://cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswi<wbr>tch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" rel="noreferrer" target="_blank">http://lists.freeswitch.org/ma<wbr>ilman/listinfo/freeswitch-user<wbr>s</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" rel="noreferrer" target="_blank">http://lists.frees<wbr>witch.org/mailman/options/<wbr>freeswitch-users</a><br>
<a href="https://freeswitch.com" rel="noreferrer" target="_blank">https://freeswitch.com</a></blockquote></div>
<br>______________________________<wbr>______________________________<wbr>_____________<br>
Professional FreeSWITCH Services<br>
<a href="mailto:sales@freeswitch.com" target="_blank">sales@freeswitch.com</a><br>
<a href="https://freeswitch.com" rel="noreferrer" target="_blank">https://freeswitch.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="https://freeswitch.com/oss" rel="noreferrer" target="_blank">https://freeswitch.com/oss</a><br>
<a href="https://freeswitch.org/confluence" rel="noreferrer" target="_blank">https://freeswitch.org/conflue<wbr>nce</a><br>
<a href="https://cluecon.com" rel="noreferrer" target="_blank">https://cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswi<wbr>tch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" rel="noreferrer" target="_blank">http://lists.freeswitch.org/ma<wbr>ilman/listinfo/freeswitch-user<wbr>s</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" rel="noreferrer" target="_blank">http://lists.frees<wbr>witch.org/mailman/options/<wbr>freeswitch-users</a><br>
<a href="https://freeswitch.com" rel="noreferrer" target="_blank">https://freeswitch.com</a><br></blockquote></div><br></div></div></div></div>
<br>______________________________<wbr>______________________________<wbr>_____________<br>
Professional FreeSWITCH Services<br>
<a href="mailto:sales@freeswitch.com">sales@freeswitch.com</a><br>
<a href="https://freeswitch.com" rel="noreferrer" target="_blank">https://freeswitch.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="https://freeswitch.com/oss" rel="noreferrer" target="_blank">https://freeswitch.com/oss</a><br>
<a href="https://freeswitch.org/confluence" rel="noreferrer" target="_blank">https://freeswitch.org/<wbr>confluence</a><br>
<a href="https://cluecon.com" rel="noreferrer" target="_blank">https://cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.<wbr>freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" rel="noreferrer" target="_blank">http://lists.freeswitch.org/<wbr>mailman/listinfo/freeswitch-<wbr>users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" rel="noreferrer" target="_blank">http://lists.<wbr>freeswitch.org/mailman/<wbr>options/freeswitch-users</a><br>
<a href="https://freeswitch.com" rel="noreferrer" target="_blank">https://freeswitch.com</a><br></blockquote></div><br></div>