WinHttp use credentials from WinInet RRS feed

  • Question

  • Hello,

    I have a website protected with a basic authentication, which launch an ActiveX using WinHttp to communicate to the same website.
    As is, it doesn't work without manual re-authentication within my application.

    I would like to somehow retrieve the first authentication credentials and re-use it with WinHttp, like WinInet does (with its Credential cache)
    I've read about WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS in https://msdn.microsoft.com/en-us/library/windows/desktop/aa384066(v=vs.85).aspx
    It is supposed to enable authentication using WinInet credentials.

    The problem is I can't make it work, and can't find any more detailed documentation or example.

    What is this "last resort" using global credentials, how is it triggered from code ?
    The credentials are "pushed down from WinInet", am I supposed to collect them somehow, or is it all wrapped by WinHttp ?

    It seems related to the other flag WINHTTP_OPTION_GLOBAL_SERVER_CREDS, is that how am I supposed to retrieve any credentials ?
    How am I supposed to fill the WINHTTP_CREDS_EX structure to make it work ?

    For now, I have tested WinHttpSetOption with WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS set to TRUE, the method returns TRUE.
    I failed setting the credentials for the appropriate scheme with WinHttpSetCredentials and NULL for username & password (ERROR_INVALID_PARAMETER as long as username is NULL or empty)
    I also tested WinHttpSetOption with WINHTTP_OPTION_GLOBAL_SERVER_CREDS and an empty WINHTTP_CREDS_EX struct with no hInternet parameter, without success (ERROR_WINHTTP_INVALID_OPTION)
    I also tried WinHttpQueryOption, with WINHTTP_OPTION_GLOBAL_SERVER_CREDS flag, without success.

    Any idea on how to make it work ?


    Friday, January 23, 2015 5:27 PM


  • Hi NFB127894,

    Based on your description, I’m afraid that it is not the correct forum for this issue, since this forum is to discuss:

    Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor.

    I am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right forum.

    If it is related to the web app, maybe you could post this issue in http://forums.asp.net where asp.net experts live in. Anyway, I move it to the moderator forum. Thanks for your understanding.

    Have a nice day,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 26, 2015 9:42 AM