/* * Just like simpleGet but with an explicit port number */ static bool get(MprTestGroup *gp, cchar *host, int port, cchar *uri, int expectCode) { MprHttp *http; int code; http = getHttp(gp); if (expectCode <= 0) { expectCode = 200; } if (host) { mprSetHttpDefaultHost(http, host); } if (port > 0) { mprSetHttpDefaultPort(http, getDefaultPort(gp) + port); } if (mprHttpRequest(http, "GET", uri, 0) < 0) { return 0; } code = mprGetHttpCode(http); assert(code == expectCode); if (code != expectCode) { mprLog(gp, 0, "get: HTTP response code %d, expected %d", code, expectCode); return 0; } assert(mprGetHttpError(http) != 0); assert(mprGetHttpContent(http) != 0); return 1; }
void getTable::update() { count ++; httpResponse = getHttp(); parser(); }
// ----------------------------------------------------------------------------- // Gets a response via http from [host]/[url] (non-blocking). When the response // is received, an event is sent to [event_handler] // ----------------------------------------------------------------------------- void Web::getHttpAsync(const string& host, const string& uri, wxEvtHandler* event_handler) { std::thread thread([=]() { // Queue wx event with http request response auto event = new wxThreadEvent(wxEVT_THREAD_WEBGET_COMPLETED); event->SetString(getHttp(host, uri)); wxQueueEvent(event_handler, event); }); thread.detach(); }
/* * Test authorization within a virtual host */ static void auth(MprTestGroup *gp) { MprHttp *http; http = getHttp(gp); assert(get(gp, NULL, 2, "/acme.html", 0)); mprSetHttpCredentials(http, "mary", "pass2"); assert(get(gp, NULL, 2, "/protected/private.html", 0)); mprResetHttpCredentials(http); }
int startRequest(MprTestGroup *gp, cchar *method, cchar *uri) { Http *http; HttpConn *conn; gp->content = 0; http = getHttp(gp); if (*uri == '/') { httpSetDefaultClientPort(http, app->port); httpSetDefaultClientHost(http, app->host); } gp->conn = conn = httpCreateConn(http, NULL, gp->dispatcher); if (httpConnect(conn, method, uri, NULL) < 0) { return MPR_ERR_CANT_OPEN; } return 0; }
static void location(MprTestGroup *gp) { MprHttp *http; char *uri; int rc, code; http = getHttp(gp); uri = "/egi/egiProgram?SWITCHES=-l%20http://www.redhat.com/"; rc = httpRequest(http, "GET", uri); assert(rc == 0); if (rc != 0) { return; } code = mprGetHttpCode(http); if (code != 302) { mprLog(gp, 0, "Client failed for %s, response code: %d, msg %s\n", uri, code, mprGetHttpMessage(http)); } }
static bool authGet(MprTestGroup *gp, char *uri, char *realm, char *user, char *password, int expectCode) { MprHttp *http; char uriBuf[MPR_MAX_STRING]; cchar *content; int rc, code, contentLength; http = getHttp(gp); if (authType) { mprSprintf(uriBuf, sizeof(uriBuf), "/%s%s", authType, uri); mprSetHttpCredentials(http, user, password); } else { mprStrcpy(uriBuf, sizeof(uriBuf), uri); mprResetHttpCredentials(http); } rc = httpRequest(http, "GET", uriBuf); if (!assert(rc == 0)) { return 0; } code = mprGetHttpCode(http); assert(code == expectCode); if (code != expectCode) { mprLog(gp, 0, "Client failed for %s, response code: %d, expected %d, msg %s\n", uriBuf, code, expectCode, mprGetHttpMessage(http)); return 0; } if (expectCode != 200) { contentLength = mprGetHttpContentLength(http); content = mprGetHttpContent(http); if (! assert(content != 0 && contentLength > 0)) { return 0; } } return 1; }
static void status(MprTestGroup *gp) { MprHttp *http; char *uri; int rc, code; http = getHttp(gp); /* * Have egiProgram exit with a 711 status */ uri = "/egi/egiProgram?SWITCHES=-s%20711"; rc = httpRequest(http, "GET", uri); assert(rc == 0); if (rc != 0) { return; } code = mprGetHttpCode(http); if (code != 711) { mprLog(gp, 0, "Client failed for %s, response code: %d, msg %s\n", uri, code, mprGetHttpMessage(http)); } }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- consoleDemoInit(); //setup the sub screen for printing iprintf("\n\n\tSimple Wifi Connection Demo\n\n"); iprintf("Connecting via WFC data ...\n"); if(!Wifi_InitDefault(WFC_CONNECT)) { iprintf("Failed to connect!"); } else { iprintf("Connected\n\n"); getHttp("www.akkit.org"); } while(1) { swiWaitForVBlank(); } return 0; }