Jump to content
C4 Forums | Control4

Using POST with c4:NetConnect


Recommended Posts

I am trying to send the following request using

POST http://ipaddress:port/keypress/home HTTP/1.1

This can easily be done through fiddler and I am able to control a Roku device with the above POST request.

What is the equivalent syntax

g_URLPacket = "/keypress/home"

c4:NetConnect(6001,port)

Or should the syntax be

g_URLPacket = "POST /keypress/home"

c4:NetConnect(6001,port)

Or is it something else to POST to be used instead of GET

Thanks,

Link to comment
Share on other sites


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")

NetConnect

C4:NetConnect(idBinding, nPort)

Function used to tell the system to make a connection. An established connection

can be validated through OnConnectionStatusChanged.

Returns

None

Parameters

idBinding - Binding ID of the network interface

nPort - Network port to connect to

Example

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

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 reply

In 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

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 reply

In 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

function PostData(strKey, strValue)

local postdata = strKey .. "=" .. strValue

local id = C4:urlPost("http://mywebsite.com/data/post/", postdata)

end

function ReceivedAsync(idTicket, strData)

print("Data received from server after post: " .. strData)

end

RyanE

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.