How to send a message in LUA language from ESP8266 to Electric Imp?

I can successfully send a message from my first imp to my second one. Now I’m trying to write a simple program in the LUA language to send a message from an ESP8266 to the same Imp. Using this program on the ESP8266:

conn=net.createConnection(net.TCP, 0)
conn:on(“connection”,function(conn, payload)
conn:send(“HEAD / HTTP/1.1\r
”…
“Host: agent.electricimp.com/...agentID… \r
”…
“Accept: /\r
”…
“User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)”…
"\r
\r
")
end)

conn:on(“receive”, function(conn, payload) print(payload) conn:close() end)
conn:connect(80,‘agent.electricimp.com’)

I get this result from the Imp Agent:

HTTP/1.1 400 Bad Request
Content-Length: 181
Content-Type: text/html
Date: Fri, 18 Mar 2016 18:11:35 GMT
Server: nginx/1.4.6 (Ubuntu)
Connection: keep-alive

I’m at the limit of my knowledge on both LUA and HTTP. Can anybody tell me what’s wrong with my LUA program or how to find out the cause of the “400 Bad Request” received from the Imp Agent ? Thanks in advance for any suggestions.

I haven’t tested this but I think you need to change:
conn:send("HEAD / HTTP/1.1\\r\ "..
to
conn:send("HEAD /...agentID... HTTP/1.1\\r\ "..

You may also want to change HEAD to either GET or PUT, depending on what you are trying to do as HEAD changes when/how the connection is closed by the agent in ways you often don’t want.

Great !! Thanks !!! This worked;

conn:on(“connection”,function(conn, payload)
conn:send(“HEAD /…agentID… HTTP/1.1\r
”…
“Host: agent.electricimp.com\r
”…
"\r
\r
")
end)