Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CHttpConnection and https

Posted on 2004-08-12
5
Medium Priority
?
2,737 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 750 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

618 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