MCPcopy Create free account
hub / github.com/azadkuh/qhttp / runClient

Function runClient

example/helloworld/main.cpp:80–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78#if defined(QHTTP_HAS_CLIENT)
79
80void runClient(QString url) {
81 using namespace qhttp::client;
82 // ensure there the url has http://
83 if ( !url.startsWith("http://") && !url.startsWith("https://") )
84 url.prepend("http://");
85
86 QHttpClient client(qApp);
87
88 bool success = client.request(qhttp::EHTTP_GET, url, [](QHttpResponse* res) {
89 // response handler, called when the HTTP headers of the response are ready
90 res->collectData();
91 // called when all data in HTTP response have been read.
92 res->onEnd([res]() {
93 // print the XML body of the response
94 qDebug("\nreceived %d bytes of http body:\n%s\n",
95 res->collectedData().size(),
96 res->collectedData().constData()
97 );
98
99 qApp->quit();
100 });
101
102 // just for fun! print headers:
103 qDebug("\n[Headers:]");
104 res->headers().forEach([](auto cit) {
105 qDebug("%s : %s", cit.key().constData(), cit.value().constData());
106 });
107 });
108
109 if ( !success ) {
110 qDebug("failed: can not send a request to %s\n", qPrintable(url));
111 return;
112 }
113
114 qApp->exec();
115}
116
117void runWeatherClient(const QString& cityName) {
118 using namespace qhttp::client;

Callers 1

mainFunction · 0.85

Calls 3

requestMethod · 0.80
forEachMethod · 0.80
collectDataMethod · 0.45

Tested by

no test coverage detected