lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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