Solved

CHttpConnection and https

Posted on 2004-08-12
5
2,323 Views
Last Modified: 2013-11-20
The Windows docs say that CHttpConnection does support https, but I haven't been able to figure out how and there are no examples I could find.  Here's the code I have:

std::string DoIt(const std::string& strServer, const std::string& strQuery)
{
    std::string strResult;
    CInternetSession *pSession;
    CHttpConnection *pConnection;
   
    pSession = new CInternetSession("test");
    pConnection = pSession->GetHttpConnection(strServer.c_str(),
                                              INTERNET_DEFAULT_HTTP_PORT,
                                              "", "");

    if (pConnection != NULL)
    {
        CHttpFile* pFile;

        pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET,
                                         strQuery.c_str(),
                                         NULL,
                                         1,
                                         NULL,
                                         NULL,
                                         INTERNET_FLAG_RELOAD);
        if (pFile != NULL)
        {
            DWORD dwStatus;

            pFile->SendRequest();
            pFile->QueryInfoStatusCode(dwStatus);

            if ((dwStatus >= 200) && (dwStatus < 300))
            {
                // Read the CHttpFile
            }
        }
    }

    delete pSession;

    return strResult;
}

A few chunks have been deleted, but all internet related calls are still there.  It works fine, I just need to make it use https instead of http.

Thanks.
0
Comment
Question by:KurtVon
  • 3
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
millsoft earned 250 total points
Comment Utility
You have to set some options on the OpenRequest:

DWORD dwRequestFlags = INTERNET_FLAG_SECURE | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_NO_AUTO_REDIRECT;

pFile = pConnection->OpenRequest( GetVerb(), m_locale.PostObject(), NULL, 1, NULL, NULL, DWORD );
0
 
LVL 5

Expert Comment

by:millsoft
Comment Utility
Of course, you also have to open the session on port 443.

So strServer on your session create line needs to read "https://www.foo.com"
0
 
LVL 5

Expert Comment

by:millsoft
Comment Utility
correction:

pFile = pConnection->OpenRequest( GetVerb(), m_locale.PostObject(), NULL, 1, NULL, NULL, dwRequestFlags );
0
 
LVL 11

Author Comment

by:KurtVon
Comment Utility
Sorry it took so long to respond.

I have it sort of working (sever error 500) but I had to drop the https://.  It took a while to confirm this was  a problem in general.  When I thought to test with http:// prepended to the server name and using the previously working non-secure method I got the same exception thrown, so I'm pretty sure that was it.

Since the server error 500 seems to show up under IE, it isn't surprising the MFC is doing it.  So I'll mark this as answered.  Thanks.
0
 
LVL 11

Author Comment

by:KurtVon
Comment Utility
Oh yeah, and the port number is specified in the GetHttpConnection.  I just used INTERNET_DEFAULT_HTTPS_PORT.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 20
Pressing cancel button with C# UI Automation 3 39
viewing source code from eclipse 13 74
lucky13 challenge 11 111
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now