The tcDspNetClientHttp class is used to provide a simple HTTP/1.1 client for the MityDSP. The GET, HEAD, POST, PUT, and DELETE methods are supported. In all cases, a standard URL string, of the format "http://<hostname or IP>:<optional port>/<file>" is used to specify the target of the command.
This is a simple example of tcDspNetClientHttp creation and usage:
#include <net/clients/DSPNetClientHttp.h> // GET a web page... { tcDspNetClientHttp::teHttpReturn rv; const char *url = "http://www.mitydsp.com/our-company/faq/"; static char buffer[8192], mime[tcDspNetClientHttp::gnMimeLength]; tcDspNetClientHttp *mpHttp = new tcDspNetClientHttp; int len = sizeof(buffer); rv = mpHttp->get(url, (void *)buffer, len, mime); printf("HTTP returned: %1d\r\n", (int)rv); printf("MIME-type: %s\r\n", (strlen(mime) > 0) ? mime : "unknown"); : } // POST a response to a form... { tcDspNetClientHttp::teHttpReturn rv; const char *url = "http://www.mitydsp.com/index.php?search=search"; const char *query = "searchwords=news&SubmitSearch=Go"; static char buffer[8192], mime[tcDspNetClientHttp::gnMimeLength]; tcDspNetClientHttp *mpHttp = new tcDspNetClientHttp; int len = sizeof(buffer); rv = mpHttp->post(url, query, strlen(query), (void *)buffer, &len, mime); printf("HTTP returned: %1d\r\n", (int)rv); printf("MIME-type: %s\r\n", (strlen(mime) > 0) ? mime : "unknown"); : } // HEAD gets existance and size info... { tcDspNetClientHttp::teHttpReturn rv; const char *url = "http://www.mitydsp.com/our-company/faq/"; static char mime[tcDspNetClientHttp::gnMimeLength]; tcDspNetClientHttp *mpHttp = new tcDspNetClientHttp; int len = 0; rv = mpHttp->head(url, len, mime); printf("HTTP returned: %1d\r\n", (int)rv); printf("MIME-type: %s\r\n", (strlen(mime) > 0) ? mime : "unknown"); printf("Content-length: %1d\r\n", len); : } // PUT a file to a server... { tcDspNetClientHttp::teHttpReturn rv; const char *url = "http://www.mitydsp.com/somefile.txt"; const char *file = "Hello, World!"; tcDspNetClientHttp *mpHttp = new tcDspNetClientHttp; rv = mpHttp->put(url, file, strlen(file), true, "text/plain"); printf("HTTP returned: %1d\r\n", (int)rv); : } // DELETE a file from the server, if allowed { tcDspNetClientHttp::teHttpReturn rv; const char *url = "http://www.mitydsp.com/somefile.txt"; tcDspNetClientHttp *mpHttp = new tcDspNetClientHttp; rv = mpHttp->del(url); printf("HTTP returned: %1d\r\n", (int)rv); : }