How to write a lua request to the REST API?

Decided to sketch a lua script to query redmine server and have not figured out how to work the functions of the packet socket and socket.http.

c = socket.connect("local.redmine", 80)

returns nil
strUrl = "/issues.xml"
strUrl = strUrl.."?key="..apiAccessKey
strUrl = strUrl.."&assigned_to_id=me"
strUrl = strUrl.."&status_id=2"
strUrl = strUrl.."&limit=100"
strUrl = strUrl.."\r\n\r\n"
res, c, cache = http.request("local.redmine", "GET", strUrl)

res reads the html code of the home page

any such variations tried

local headers = {}

headers["Content-Type"] = "application/json"
headers["X-Parse-Application-Id"] = "LuaTest"
headers["X-Redmine-API-Key"] = apiAccessKey

local body = ""
local params = {}
params.headers = headers
params.body = body
res, c, cache = http.request("local.redmine", "GET", networkListener, params)


In C++ it looked and it is currently working
SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
 struct hostent *host;
 host = gethostbyname("local.redmine");
 SOCKADDR_IN SockAddr;
SockAddr.sin_port=htons(80);
SockAddr.sin_family was=AF_INET;
 SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
connect(Socket,(SOCKADDR*)(&SockAddr),sizeof(SockAddr));

 string strUrl = "GET /issues.xml";
 strUrl += "?key=" + apiAccessKey;
 strUrl += "&assigned_to_id=me";
 strUrl += "&status_id=2";
 strUrl += "&limit=100";
 strUrl += "\r\n\r\n";

 send(Socket, strUrl.c_str(), strUrl.length(), 0);
 char buffer[10001];
 int nDataLength;
 while ((nDataLength = recv(Socket,buffer, 10000,0)) > 0){
 buffer[nDataLength] = 0;
 m_strOut += buffer;
 strXmlAnswer += buffer;
}
 closesocket(Socket);
March 12th 20 at 08:01
1 answer
March 12th 20 at 08:03
Socket seems like it is http, so you can use the following:

local http = require("socket.http")

local body, code, headers, status = http.request("http://example.com/lua.php")

if body then
 - if there is an answer - write it
print(body)
else 
 - if not - most likely there was some kind of mistake. Output code error.
print(code)
end

Find more questions by tags LuaRESTful APIWeb serversRedmine