MityDSP Documentation Index

tcDspNetClientHttp

Introduction

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.

Note:
The tcDspNetClientHttp class can support a secure socket interface to a server via the use of a "helper class" to provide the required encryption. To use this capability, derive a helper from tcDspNetSslHelper and register it via the ssl_helper method. If no helper is registered, "https://" connections will fail.
See also:
MityDSP::tcDspNetClientHttp Class Reference
DspNetSslHelper.h

Example

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

     :
 } 

  
Generated on Fri Sep 23 16:34:01 2011 for MityDSP Net by  Doxygen Version 1.6.1
Copyright © 2009, Critical Link LLC, All rights reserved.