lua-http - How to send a POST?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

lua-http - How to send a POST?

Russell Haley
Hi, 

The title says it all, I need to create an HTTP(s) POST request like this:

POST /auth/signin?username=NotARealBoy&password=NotARealPassword HTTP/1.1
Content-Type: application/x-www-form-urlencoded
cache-control: no-cache
Postman-Token: 71fffce7-5133-4bdb-bd6b-401213b0338f
User-Agent: PostmanRuntime/7.6.1
Accept: */*
Host: canary-dev.spe.local:8083
cookie: connect.sid=s%3ARCCVD1m-MOmuTsd6RGm999glTcsE3t35.gTlrFDa5ZntQwAmqFg%2B3Y%2Fk14zeQzp7z%2Fg97RSbxebc
accept-encoding: gzip, deflate
content-length: 51
Connection: keep-alive

username=NotARealBoy&password=NotARealPassword

/*******************/

Everything I've tried is still just a GET request. I'll also need to implement PUT and DELETE. I now there was discussions with Andrew Starks about REST request code for a server side lua-http implementation, but this is client side so I don't know/think that the suggested libraries are applicable.

Thanks,
Russ

p.s. I'm not going to bother adding my crappy prototype code again.
Reply | Threaded
Open this post in threaded view
|

Re: lua-http - How to send a POST?

Daurnimator
On Sat, 4 May 2019 at 09:55, Russell Haley <[hidden email]> wrote:
> The title says it all, I need to create an HTTP(s) POST request like this:

Check the example in the repository:
https://github.com/daurnimator/lua-http/blob/29524fa93e8ca71532375702913f281db52f4f2c/examples/simple_request.lua#L17

Reply | Threaded
Open this post in threaded view
|

Re: lua-http - How to send a POST?

Russell Haley


On Fri, May 3, 2019 at 6:19 PM Daurnimator <[hidden email]> wrote:
On Sat, 4 May 2019 at 09:55, Russell Haley <[hidden email]> wrote:
> The title says it all, I need to create an HTTP(s) POST request like this:

Check the example in the repository:
https://github.com/daurnimator/lua-http/blob/29524fa93e8ca71532375702913f281db52f4f2c/examples/simple_request.lua#L17

You know I might become a half decent developer if I could learn to read. I wonder how many times have I looked at that example: ten, fifteen??? Please don't slap me if we ever meet in person, though you'd be perfectly justified doing so. :-/

Thanks again,
Russ
Reply | Threaded
Open this post in threaded view
|

Re: lua-http - How to send a POST?

"Гришин В.С."
In reply to this post by Russell Haley
example from my script . version  of lua is 5.1


http = require 'socket.http'

http.TIMEOUT = 1 -- sets the timeout for all I/O operations;
http.USERAGENT = "goip_smsd" --: default user agent reported to server.

            reqbody =
"line="..channel.."&smskey="..list[1].."&action=SMS&telnum="..list[2].."&smscontent="..list[1]..list[3].."&send=Send"

             local body, code, headers, status = http.request {method =
"POST",
                                                    url =
"http://"..host.."/default/en_US/sms_info.html",
                                                    headers = {
["Authorization"] = "Basic "..(mime.b64("USERNAME:PASSWORD")),
["content-length"] = string.len(reqbody),
["content-type"]   = "application/x-www-form-urlencoded"},
                                                    source =
ltn12.source.string(reqbody)
--                                                 sink =
ltn12.sink.file(io.stdout)
                                                    }
             code = tostring(code)
             if body ~= nil and code == '200' then

                 print('body:' .. tostring(body))
                 print('code:' .. tostring(code))
--print('headers:' .. util.tableToString(headers))
                 for k,v in pairs(headers) do
                     print (k.." "..v)
                 end
                 print("POST send_sms coro: " .. coro .. "status:" ..
tostring(status))
--print('respbody:' .. tostring(respbody[1]))
                 return true
             else
                 return false
             end


see

http://w3.impa.br/~diego/software/luasocket/installation.html

http://w3.impa.br/~diego/software/luasocket/http.html


04.05.2019 2:54, Russell Haley пишет:

> Hi,
>
> The title says it all, I need to create an HTTP(s) POST request like this:
>
> POST /auth/signin?username=NotARealBoy&password=NotARealPassword HTTP/1.1
> Content-Type: application/x-www-form-urlencoded
> cache-control: no-cache
> Postman-Token: 71fffce7-5133-4bdb-bd6b-401213b0338f
> User-Agent: PostmanRuntime/7.6.1
> Accept: */*
> Host: canary-dev.spe.local:8083
> cookie:
> connect.sid=s%3ARCCVD1m-MOmuTsd6RGm999glTcsE3t35.gTlrFDa5ZntQwAmqFg%2B3Y%2Fk14zeQzp7z%2Fg97RSbxebc
> accept-encoding: gzip, deflate
> content-length: 51
> Connection: keep-alive
>
> username=NotARealBoy&password=NotARealPassword
>
> /*******************/
>
> Everything I've tried is still just a GET request. I'll also need to
> implement PUT and DELETE. I now there was discussions with Andrew
> Starks about REST request code for a server side lua-http
> implementation, but this is client side so I don't know/think that the
> suggested libraries are applicable.
>
> Thanks,
> Russ
>
> p.s. I'm not going to bother adding my crappy prototype code again.

Vladislav Grishin