Solved

CHttpConnection and https

Posted on 2004-08-12
5
2,564 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
millsoft earned 250 total points
ID: 11788919
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
ID: 11788923
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
ID: 11788925
correction:

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

Author Comment

by:KurtVon
ID: 11797077
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
ID: 11797086
Oh yeah, and the port number is specified in the GetHttpConnection.  I just used INTERNET_DEFAULT_HTTPS_PORT.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

719 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