Help needed for HTTPS download

Discussion in 'C++' started by Camel, May 28, 2005.

  1. Camel

    Camel Guest

    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;
    }
    Camel, May 28, 2005
    #1
    1. Advertising

  2. Camel

    red floyd Guest

    Camel wrote:
    > 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-----------------
    >
    > [redacted]


    Your question relates to the HTTPS implementation on your system. There
    is no C++ language question. Not to mention the fact that your code is
    C, not C++.

    Recommend you post to a Microsoft group:

    comp.os.ms-windows.programmer or
    comp.os.ms-windows.programmer.networks
    red floyd, May 28, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. StefanSt
    Replies:
    3
    Views:
    1,146
    StefanSt
    Aug 24, 2005
  2. McCann, Brian

    M2Crypto and general HTTPS help needed

    McCann, Brian, Jul 25, 2006, in forum: Python
    Replies:
    0
    Views:
    319
    McCann, Brian
    Jul 25, 2006
  3. Axel
    Replies:
    8
    Views:
    1,066
    Adrienne Boswell
    Apr 27, 2009
  4. jotto
    Replies:
    4
    Views:
    374
    jotto
    Oct 2, 2006
  5. Naveen Dhanuka
    Replies:
    1
    Views:
    266
Loading...

Share This Page