Lua socket error on connection -


i'm trying make http get, using lua socket:

local client = socket.connect('warm-harbor-2019.herokuapp.com',80) if client     client:send("get /get_tweets http/1.0\r\n\r\n")       s, status, partial = client:receive(1024)     end end 

i expect s tweet, since i'm making returns one. i'm getting:

http/1.1 404 object not found 

here runnable version of code example (that exhibit problem described):

local socket = require "socket" local client = socket.connect('warm-harbor-2019.herokuapp.com',80) if client     client:send("get /get_tweets http/1.0\r\n\r\n")     local s, status, partial = client:receive(1024)     print(s) end 

if read error page returned, can see title heroku | no such app.

the reason heroku router works when host header provided. easiest way use actual http module of luasocket instead of tcp directly:

local http = require "socket.http" local s, status, headers = http.request("http://warm-harbor-2019.herokuapp.com/get_tweets") print(s) 

if cannot use socket.http can pass host header manually:

local socket = require "socket" local client = socket.connect('warm-harbor-2019.herokuapp.com',80) client:send("get /get_tweets http/1.0\r\nhost: warm-harbor-2019.herokuapp.com\r\n\r\n") local s, status, partial = client:receive(1024) print(s, status, partial) 

with version of luasocket, s nil, status "closed" , partial contain full http response (with headers etc).


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -