Lua POST请求包含垃圾

时间:2019-06-20 21:34:34

标签: lua http-post

我正在尝试发送POST请求,但是注意到我尝试访问的端点似乎不喜欢该请求,因此为了调查这种情况,我在使用{侦听时将请求重定向到localhost {1}}并看到以下请求:

nc

我正在使用的代码,以防万一:

nc -vlp 444

Connection from 127.0.0.1:53812
POST / HTTP/1.1
Host: localhost:4444
TE: trailers
Cookie: 
Content-Type: application/x-www-form-urlencoded
Connection: close, TE
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0

27 -- this line shouldn't be there
username=username&password=password
0  -- also this one

认为这是一个问题, local http = require("socket.http") -- even tried ssl.https ... function Session:post(url, payload) -- payload = "username=username&password=password" local response = Response local body = { } local r, c, h, s = http.request{ url = url, method = "POST", sink = ltn12.sink.table(body), source = ltn12.source.string(payload), headers = { ["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0", ["Content-Type"] = "application/x-www-form" }, } -- you can ignore this response.code = c response.status = s response.body = table.concat(body) self.cookies:parse(h["set-cookie"]) return response end 我直接在项目中复制了它的源代码,但是很快发现它只返回了有效载荷而没有实际更改

ltn12

1 个答案:

答案 0 :(得分:0)

通过添加Content-Length标头来解决此问题。