C++: Get/Post Request POCO lib
Get/Post Request POCO lib ... Reveal Code
//----------GET string GetRequest(string reference) { try { string text; URI uri(reference); HTTPClientSession session(uri.getHost(), uri.getPort()); string path(uri.getPathAndQuery()); if (path.empty()) path = "/"; HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1); req.set("User-Agent", "Poco"); //session.setProxy("120.203.215.6", 85); session.sendRequest(req); HTTPResponse res; istream &is = session.receiveResponse(res); StreamCopier::copyToString(is, text); return text; } catch(...) { return ""; } } void PostRequest(string reference, string id) { try { string text; URI uri(reference); HTTPClientSession session(uri.getHost(), uri.getPort()); session.setKeepAlive(true); string path(uri.getPathAndQuery()); if (path.empty()) path = "/"; HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1); req.setContentType("application/x-www-form-urlencoded"); req.add("Accept", "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/ x-xbitmap, */*;q=0.1"); req.add("Accept-Encoding","gzip,deflate"); req.setKeepAlive(true); req.set("User-Agent", "Opera/9.80 (Windows NT 6.2; WOW64) Presto/2.12.388 Version/12.15"); req.set("Cookie", "amcu_nn=1; advmaker_pop=1; PHPSESSID=6db1c4beb65ff4346c351459b1caf194"); std::string reqBody("action=post&lnk="+id); req.setContentLength( reqBody.length() ); session.sendRequest(req) << reqBody; } catch(...) { cout<<"fail"; } }