add http_client library, using libcurl
take out common http entities to http_common dir
This commit is contained in:
41
main.cpp
41
main.cpp
@@ -1,8 +1,9 @@
|
||||
#include "pihttpclient.h"
|
||||
#include "pip.h"
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
PIKbdListener kbd;
|
||||
// PIKbdListener kbd;
|
||||
const char * pageTitle = "<!DOCTYPE html>"
|
||||
"<html>"
|
||||
"<body>"
|
||||
@@ -12,16 +13,50 @@ const char * pageTitle = "<!DOCTYPE html>"
|
||||
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
PIHTTPServer server;
|
||||
server.listen({"127.0.0.1:7777"});
|
||||
server.registerUnhandled([](const PIHTTP::MessageConst & msg) -> PIHTTP::MessageMutable {
|
||||
PIHTTP::MessageMutable ret;
|
||||
piCout << "server rec:\n\tpath: %1\n\tmethod: %2\n\tbody: %3"_a.arg(msg.path())
|
||||
.arg((int)msg.method())
|
||||
.arg(PIString::fromUTF8(msg.body()));
|
||||
ret.setCode(PIHTTP::Code::BadRequest);
|
||||
ret.setBody(PIByteArray::fromAscii("hello client! 0123456789"));
|
||||
return ret;
|
||||
});
|
||||
|
||||
PIHTTP::MessageMutable req;
|
||||
req.setBody(PIByteArray::fromAscii("hello server!"));
|
||||
auto * c = PIHTTPClient::create("http://127.0.0.1:7777/api", PIHTTP::Method::Get, req);
|
||||
c->onFinish([](PIHTTP::MessageConst r) {
|
||||
piCout << "finish" << (int)r.code();
|
||||
piCout << "headers" << r.headers();
|
||||
piCout << "body" << PIString::fromUTF8(r.body());
|
||||
})
|
||||
->onError([c](PIHTTP::MessageConst r) {
|
||||
piCout << "error" << (int)r.code();
|
||||
piCout << "msg" << c->lastError();
|
||||
})
|
||||
->onAbort([c](PIHTTP::MessageConst r) {
|
||||
piCout << "abort" << (int)r.code();
|
||||
piCout << "msg" << c->lastError();
|
||||
})
|
||||
->start();
|
||||
piMSleep(500);
|
||||
server.stop();
|
||||
// c->abort();
|
||||
// piMSleep(500);
|
||||
return 0;
|
||||
// piCout << PIString::readableSize(PISystemMonitor::usedRAM());
|
||||
|
||||
PIVector<int> vi;
|
||||
/*PIVector<int> vi;
|
||||
piForTimes(10) {
|
||||
piSleep(2.);
|
||||
vi.enlarge(1000000);
|
||||
piCout << "now" << vi.size() << vi.capacity();
|
||||
}
|
||||
|
||||
piSleep(5.);
|
||||
piSleep(5.);*/
|
||||
/*kbd.enableExitCapture();
|
||||
|
||||
PIHTTPServer server;
|
||||
|
||||
Reference in New Issue
Block a user