locked
Using Windows::Web::Http::HttpClient with authentication (username & password)

    Question

  • Hi,

    I'm trying to create a Windows Store App in C++ for WebDAV/CalDAV/CardDAV purposes.  I need to support authentication (username & password) for the vast majority of this solution and I was looking at Windows::Web::Http::HttpClient.  Does anybody have a code sample in C++ on how to do this?

    I found an article about using HttpClientHandler, but it seems to be about System.Net.Http and if I try to use HttpClientHandler I get:

    error C2039: 'HttpClientHandler' : is not a member of 'Windows::Web::Http'

    Any code sample or help would be greatly appreciated.

    Thanks,

    Red

    Tuesday, March 18, 2014 5:48 PM

Answers

  • You'll want to use the Windows.Web.Http HttpClient, not the System.Net one -- they are quite similar, but there are enough differences to be noticeable.  In particular, you'll want an HttpFilter, not a handler.

    Check out the HttpClient sample here; it include C++ code.

    Additionally, the Web Authentication Broker shows how to set up a filter to handle auth (and has sample filters for OAuth and OAuth2); get it here.

    Lastly, take a look at our HttpClient poster from here; it shows all the important classes and how they fit together.  Sorry, the code samples on it are C# only, but it's pretty simple to convert.


    Network Developer Experience Team (Microsoft)

    Thursday, March 20, 2014 5:48 PM

All replies

  • What type of authentication does your Web Server support? Does it respond back with WWW-Authenticate header to request authentication or do you want to perform custom authentication by directly passing in the HTTP Authorization header?


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Tuesday, March 18, 2014 8:28 PM
    Moderator
  • You'll want to use the Windows.Web.Http HttpClient, not the System.Net one -- they are quite similar, but there are enough differences to be noticeable.  In particular, you'll want an HttpFilter, not a handler.

    Check out the HttpClient sample here; it include C++ code.

    Additionally, the Web Authentication Broker shows how to set up a filter to handle auth (and has sample filters for OAuth and OAuth2); get it here.

    Lastly, take a look at our HttpClient poster from here; it shows all the important classes and how they fit together.  Sorry, the code samples on it are C# only, but it's pretty simple to convert.


    Network Developer Experience Team (Microsoft)

    Thursday, March 20, 2014 5:48 PM
  • BTW -- be sure to use an HTTPS connection for username+password; otherwise you're sending security data in the clear.

    Network Developer Experience Team (Microsoft)

    Friday, March 21, 2014 8:02 PM