Error on http GET request
Posted: Thu Mar 31, 2016 10:06 pm
Been trying a variety of methods to create an http get request. This is my current code:
37 -- create http client
38 conn=net.createConnection(net.TCP, 0)
39 conn:on("receive", function(conn, payload) print(payload) end)
40 conn.connect(80,HOST)
41 conn.send("GET " .. param.. "HTTP/1.1\r\n")
42 conn:send("Host: "..HOST.."\r\n")
43 conn.send("Accept: */*\r\n")
44 conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
45 conn:send("\r\n")
46 conn:on("sent",function(conn)
47 conn:close()
48 end)
The code fails with "file.lua:40: Bad argument #1 to 'connect' (net.socketexpected, go number). It's almost a straight copy out of documentation from a variety of forums, so I'm really scratching my head as to why it's failing.
37 -- create http client
38 conn=net.createConnection(net.TCP, 0)
39 conn:on("receive", function(conn, payload) print(payload) end)
40 conn.connect(80,HOST)
41 conn.send("GET " .. param.. "HTTP/1.1\r\n")
42 conn:send("Host: "..HOST.."\r\n")
43 conn.send("Accept: */*\r\n")
44 conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
45 conn:send("\r\n")
46 conn:on("sent",function(conn)
47 conn:close()
48 end)
The code fails with "file.lua:40: Bad argument #1 to 'connect' (net.socketexpected, go number). It's almost a straight copy out of documentation from a variety of forums, so I'm really scratching my head as to why it's failing.