The simple HTTP server sample demonstrates how to add HTTP client functionality to your C application. The AppWeb HTTP client allows applications to retrieve documents using GET and POST HTTP method calls. The sample is a main program that requests the home page from https://mbedthis.com.
Files
simpleClient.cpp
Source Code
simpleClient.cpp
// // Copyright (c) Mbedthis Software LLC, 2003-2004. All Rights Reserved. // /// @file simpleClient.cpp /// @brief Simple client using the GET method to retrieve a web page. /// /// This sample demonstrates retrieving content using the HTTP GET /// method via the Client class. /// ////////////////////////////// Includes //////////////////////////////// #include "appWeb/appWeb.h" ////////////////////////////////// Code //////////////////////////////// int main(int argc, char** argv) { MaClient *client; Mpr mpr("simpleClient"); char *content; int code, contentLen; // // Start the Mbedthis Portable Runtime // mpr.start(); // // Get a client object to work with. We can issue multiple // requests with this one object. // client = new MaClient(); // // Get a URL // if (client->getRequest("https://mbedthis.com/index.html") < 0) { mprFprintf(MPR_STDERR, "Can't get URL"); exit(2); } // // Examine the HTTP response HTTP code. 200 is success. // code = client->getResponseCode(); if (code != 200) { mprFprintf(MPR_STDERR, "Server responded with code %d\n", code); exit(1); } // // Get the actual response content // content = client->getResponseContent(&contentLen); if (content) { mprPrintf("Server responded with:\n%s\n", content); } delete client; return 0; }
|