1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 15:45:07 +00:00
serenity/Applications/Downloader/main.cpp
Andreas Kling ee83b1bcf4 LibCore: Use URL in CHttpRequest
Now there's just CHttpRequest::set_url(URL), no need to specify the
host, port and path manually anymore.

Updated ChanViewer and Downloader for the API change.
2019-08-10 19:32:03 +02:00

29 lines
883 B
C++

#include <LibCore/CHttpRequest.h>
#include <LibCore/CHttpResponse.h>
#include <LibCore/CNetworkJob.h>
#include <LibGUI/GApplication.h>
#include <stdio.h>
int main(int argc, char** argv)
{
GApplication app(argc, argv);
CHttpRequest request;
request.set_url("http://www.google.com/");
auto job = request.schedule();
job->on_finish = [&job](bool success) {
if (!success) {
dbgprintf("on_finish: request failed :(\n");
return;
}
auto& response = static_cast<const CHttpResponse&>(*job->response());
printf("%s{%p}: on_receive: code=%d\n", job->class_name(), job, 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();
}