esmadja Posted September 9, 2012 Share Posted September 9, 2012 I am trying to send the following request using POST http://ipaddress:port/keypress/home HTTP/1.1This can easily be done through fiddler and I am able to control a Roku device with the above POST request.What is the equivalent syntaxg_URLPacket = "/keypress/home"c4:NetConnect(6001,port)Or should the syntax beg_URLPacket = "POST /keypress/home"c4:NetConnect(6001,port)Or is it something else to POST to be used instead of GETThanks, Link to comment Share on other sites More sharing options...
alanchow Posted September 9, 2012 Share Posted September 9, 2012 NetConnect will only connect to the server. Note that this can be any socket and is not limited to web servers.SendToNetwork will send your string. Link to comment Share on other sites More sharing options...
esmadja Posted September 9, 2012 Author Share Posted September 9, 2012 Thanks for the reply.Are you saying that only c4:SendToNetwork can send a POST (instead of an http GET) request?The reason I ask is that the doc for NetConnect does say that after the connection is established, the g_URLPacket will be sent.So would this work to send a POST request of /kepress/Home to the IP address which is bound to 6001 on port 8060?c4:NetConnect(6001, 8060)c4:SendToNetwork(6001,8060,"POST /keypress/Home")NetConnectC4:NetConnect(idBinding, nPort)Function used to tell the system to make a connection. An established connectioncan be validated through OnConnectionStatusChanged.Returns NoneParameters idBinding - Binding ID of the network interface nPort - Network port to connect toExample The following example comes from: [weatherbug.c4i]: -- Connect to WeatherBug HTTP server. Once it's connected, the g_URLPacket will be sent.C4:NetConnect(6001, 80)NetConnect will only connect to the server. Note that this can be any socket and is not limited to web servers.SendToNetwork will send your string. Link to comment Share on other sites More sharing options...
RyanE Posted September 9, 2012 Share Posted September 9, 2012 The 'raw' Control4 network functionality does *not* implement HTTP for you.Calling C4:NetConnect is just saying 'make a connection to a server'. You still have to:* Wait for the connection to be made (OnConnectionStatusChanged will indicate when it is connected / disconnected)* Send the request (including full HTTP headers)* Wait for the replyIn 2.2 and later, there are urlGet and urlPost methods, which *do* HTTP, as opposed to C4:NetConnect.RyanE Link to comment Share on other sites More sharing options...
esmadja Posted September 10, 2012 Author Share Posted September 10, 2012 Thanks with your help I got it.The 'raw' Control4 network functionality does *not* implement HTTP for you.Calling C4:NetConnect is just saying 'make a connection to a server'. You still have to:* Wait for the connection to be made (OnConnectionStatusChanged will indicate when it is connected / disconnected)* Send the request (including full HTTP headers)* Wait for the replyIn 2.2 and later, there are urlGet and urlPost methods, which *do* HTTP, as opposed to C4:NetConnect.RyanE Link to comment Share on other sites More sharing options...
RyanE Posted September 11, 2012 Share Posted September 11, 2012 function PostData(strKey, strValue) local postdata = strKey .. "=" .. strValue local id = C4:urlPost("http://mywebsite.com/data/post/", postdata)endfunction ReceivedAsync(idTicket, strData) print("Data received from server after post: " .. strData)endRyanE Link to comment Share on other sites More sharing options...
RyanE Posted September 11, 2012 Share Posted September 11, 2012 Sorry, at CEDIA. A bit late with the reply...RyanE Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.