Help needed for HTTPS download

C

Camel

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;
}
 
R

red floyd

Camel said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top