Functions | |
| int | WebClient_Get (int address, int port, char *hostname, char *path, char *buffer, int buffer_size) |
| Performs an HTTP GET operation to the path at the address / port specified. | |
| int | WebClient_Post (int address, int port, char *hostname, char *path, char *buffer, int buffer_length, int buffer_size) |
| Performs an HTTP POST operation to the path at the address / port specified. | |
The web client system allows the Make Controller to get/post data to a webserver. This makes it straightforward to use the Make Controller as a source of data for your web apps.
Note that these functions make liberal use of printf-style functions, which can require lots of memory to be allocated to the task calling them.
There's currently not a method provided for name resolution - you can always ping the server you want to communicate with to see its IP address, and just use that.
See Network_DnsGetHostByName() for a way to get the address of a particular web site.
| int WebClient_Get | ( | int | address, | |
| int | port, | |||
| char * | hostname, | |||
| char * | path, | |||
| char * | buffer, | |||
| int | buffer_size | |||
| ) |
Performs an HTTP GET operation to the path at the address / port specified.
Reads through the HTTP header and copies the data into the buffer you pass in. Because sites can often be slow in their responses, this will wait up to 1 second (in 100 ms. intervals) for data to become available.
Some websites seem to reject connections occassionally - perhaps because we don't supply as much info to the server as a browser might, for example. Simpler websites should be just fine.
Note that this uses lots of printf style functions and may require a fair amount of memory to be allocated to the task calling it. The result is returned in the specified buffer.
| address | The IP address of the server to get from. Usually created using the IP_ADDRESS( ) macro. | |
| port | The port to connect on. Usually 80 for HTTP. | |
| hostname | A string specifying the name of the host to connect to. When connecting to a server that does shared hosting, this will specify who to connect with. | |
| path | The path on the server to connect to. | |
| buffer | A pointer to the buffer read back into. | |
| buffer_size | An integer specifying the actual size of the buffer. |
int addr = IP_ADDRESS( 72, 249, 53, 185); // makingthings.com is 72.249.53.185 int bufLength = 100; char myBuffer[bufLength]; int getSize = WebClient_Get( addr, 80, "www.makingthings.com", "/test/path", myBuffer, bufLength );
Definition at line 77 of file webclient.c.
| int WebClient_Post | ( | int | address, | |
| int | port, | |||
| char * | hostname, | |||
| char * | path, | |||
| char * | buffer, | |||
| int | buffer_length, | |||
| int | buffer_size | |||
| ) |
Performs an HTTP POST operation to the path at the address / port specified.
The actual post contents are found read from a given buffer and the result is returned in the same buffer.
| address | The IP address of the server to post to. | |
| port | The port on the server you're connecting to. Usually 80 for HTTP. | |
| hostname | A string specifying the name of the host to connect to. When connecting to a server that does shared hosting, this will specify who to connect with. | |
| path | The path on the server to post to. | |
| buffer | A pointer to the buffer to write from and read back into. | |
| buffer_length | An integer specifying the number of bytes to write. | |
| buffer_size | An integer specifying the actual size of the buffer. |
// we'll post a test message to www.makingthings.com/post/path int addr = IP_ADDRESS( 72, 249, 53, 185); // makingthings.com is 72.249.53.185 int bufLength = 100; char myBuffer[bufLength]; sprintf( myBuffer, "A test message to post" ); int result = WebClient_Post( addr, 80, "www.makingthings.com", "/post/path", myBuffer, strlen("A test message to post"), bufLength );
Definition at line 179 of file webclient.c.