summaryrefslogtreecommitdiff
path: root/Applications/Downloader/main.cpp
blob: dcca9f086bffa3327c4a1f77e48b22bd6f654020 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <LibGUI/GApplication.h>
#include <LibGUI/GHttpRequest.h>
#include <LibGUI/GHttpResponse.h>
#include <LibGUI/GNetworkJob.h>
#include <stdio.h>

int main(int argc, char** argv)
{
    GApplication app(argc, argv);

    GHttpRequest request;
    request.set_hostname("www.google.com");
    request.set_path("/");

    auto job = request.schedule();
    job->on_finish = [&job] (bool success) {
        if (!success) {
            dbgprintf("on_finish: request failed :(\n");
            return;
        }
        auto& response = static_cast<const GHttpResponse&>(*job->response());
        printf("on_receive: code=%d\n", response.code());
        printf("payload:\n");
        printf("%s", response.payload().pointer());
        printf("payload was %d bytes\n", response.payload().size());
    };

    printf("Entering main loop...\n");
    return app.exec();
}