Created
March 19, 2015 02:33
-
-
Save aleks-f/5f92ba918e5bb800dff3 to your computer and use it in GitHub Desktop.
Test to verify the problem reported on [Stack Overflow](http://stackoverflow.com/questions/29118669/client-digest-authentication-with-poco)
This file contains hidden or 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> | |
using namespace Poco::Net; | |
int main() | |
{ | |
HTTPClientSession session("httpbin.org"); | |
HTTPRequest request( | |
"GET", | |
// "http://httpbin.org/basic-auth/user/passwd", // basic | |
"http://httpbin.org/digest-auth/auth/user/passwd", // digest | |
HTTPMessage::HTTP_1_1); | |
session.sendRequest(request); | |
HTTPResponse response; | |
session.receiveResponse(response); | |
poco_assert(HTTPResponse::HTTP_UNAUTHORIZED == response.getStatus()); | |
HTTPCredentials creds("user", "passwd"); | |
std::cout << response.get("WWW-Authenticate") << std::endl; | |
creds.authenticate(request, response); | |
std::cout << std::endl << request.get("Authorization") << std::endl; | |
session.sendRequest(request); | |
response.clear(); | |
std::istream& bodyStream = session.receiveResponse(response); | |
poco_assert(HTTPResponse::HTTP_UNAUTHORIZED != response.getStatus()); | |
poco_assert(HTTPResponse::HTTP_OK == response.getStatus()); | |
std::ostringstream strStream; | |
Poco::StreamCopier::copyStream(bodyStream, strStream); | |
poco_assert("" != strStream.str()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment