Created
March 22, 2015 18:44
-
-
Save obiltschnig/348a1cddc3d0b823e8ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Poco/Net/HTTPRequest.h> | |
#include <Poco/Net/HTTPResponse.h> | |
#include <Poco/Net/HTTPClientSession.h> | |
#include <Poco/StreamCopier.h> | |
#include <Poco/Net/HTTPCredentials.h> | |
#include <sstream> | |
#include <iostream> | |
using namespace Poco::Net; | |
int main() | |
{ | |
try | |
{ | |
HTTPClientSession session("httpbin.org"); | |
HTTPRequest request( | |
"GET", | |
"/digest-auth/auth/user/passwd", | |
HTTPMessage::HTTP_1_1); | |
session.sendRequest(request); | |
Poco::Net::NameValueCollection cookies; | |
cookies.set("fake", "fake_value"); | |
HTTPResponse response; | |
session.receiveResponse(response); | |
poco_assert(HTTPResponse::HTTP_UNAUTHORIZED == response.getStatus()); | |
response.write(std::cout); | |
HTTPCredentials creds("user", "passwd"); | |
creds.authenticate(request, response); | |
request.setCookies(cookies); | |
request.write(std::cout); | |
session.sendRequest(request); | |
response.clear(); | |
std::istream& bodyStream = session.receiveResponse(response); | |
response.write(std::cout); | |
Poco::StreamCopier::copyStream(bodyStream, std::cout); | |
} | |
catch (Poco::Exception& exc) | |
{ | |
std::cerr << exc.displayText() << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment