Newsgroups : Microsoft : microsoft.public.inetsdk.programming.wininet : 2005 May : Help needed for my HTTPS program

www.cryer.info
Managed Newsgroup Archive

Help needed for my HTTPS program

Subject:Help needed for my HTTPS program
Posted by:"Camel" (jiao_he_..@yahoo.com)
Date:Fri, 27 May 2005 23:28:26 GMT

Hello All,

I have a short program (see below ) that downloads a secure page. It worked
fine when I changed in the InternetConnect function
        server name to:  www.paypal.com
        port to: INTERNET_DEFAULT_HTTPS_PORT
and changed in the HttpOpenRequest
        object name to: index.html

However, when I changed the code to download a localhost file login.html, it
printed nonsensical code. I installed and configured Tomcat on my PC. The
server runs on port 8443. I can access Tomcat server and view login.html
through HTTPS protocol in IE. Everything seemed fine in IE.

What could be the problem with my code below?
Thank you in advance for your help.

---------------my code-----------------

#include<windows.h>
#include<wininet.h>
#include<stdio.h>

int main() {

    HINTERNET Initialize,hConnect,hReq;
    DWORD dwBytes;
    char ch;

    Initialize = InternetOpen
("httpsexample",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
    hConnect = InternetConnect (
                Initialize,              // InternetOpen handle
                "localhost",             // Server  name
                8443,                    // HTTPS port
                "",                      // User name
                "",                      //  User password
                INTERNET_SERVICE_HTTP,   // Service
                0,                       // Flags
                0                        // Context
                           );

    hReq = HttpOpenRequest (
                hConnect,                   // InternetConnect handle
                "GET",                      // Method
                "",                         // Object name
                HTTP_VERSION,               // Version
                "",                         // Referrer
                NULL,                       // Extra headers
                INTERNET_FLAG_SECURE && INTERNET_FLAG_IGNORE_CERT_CN_INVALID
&&    INTERNET_FLAG_IGNORE_CERT_DATE_INVALID  ,  // Flags
                0                           // Context
                          );


    hReq = HttpOpenRequest(hConnect,NULL,"/login.html",NULL,NULL,NULL,0,0);

    if(HttpSendRequest(hReq,NULL,0,NULL,0))
    {
        while(InternetReadFile(hReq,&ch,1,&dwBytes))
        {
            if(dwBytes != 1)break;
            putchar(ch);
        }
    }

/*close file , terminate server connection and
    deinitialize the wininet library*/
    InternetCloseHandle(hReq);
    InternetCloseHandle(hConnect);
    InternetCloseHandle(Initialize);
    return 0;
}

Replies:

www.cryer.info
Managed Newsgroup Archive