Discussion:
Help needed for my HTTPS program
(too old to reply)
Camel
2005-05-27 23:28:26 UTC
Permalink
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;
}
Stephen Sulzer
2005-06-01 07:39:19 UTC
Permalink
When you create the request handle for the request to
"https://localhost:8443/login.html", what flags do you pass to
HttpOpenRequest? Do you pass the INTERNET_FLAG_SECURE flag to
HttpOpenRequest? You do not in the code you showed. You need to specify
INTERNET_FLAG_SECURE to HttpOpenRequest if the request is to go over SSL.

- Stephen
Camel
2005-06-01 21:05:31 UTC
Permalink
Yes, I pass the INTERNET_FLAG_SECURE. It is in the code.
Post by Stephen Sulzer
When you create the request handle for the request to
"https://localhost:8443/login.html", what flags do you pass to
HttpOpenRequest? Do you pass the INTERNET_FLAG_SECURE flag to
HttpOpenRequest? You do not in the code you showed. You need to specify
INTERNET_FLAG_SECURE to HttpOpenRequest if the request is to go over SSL.
- Stephen
a***@netvision.net.il
2005-06-16 17:58:40 UTC
Permalink
The certificate you installed for your secure Tomcat is registered
either for 127.0.0.1 or for localhost, or for your host DNS name. Make
sure that you access the login.html page according to this name. If you
choose, you may add the flag INTERNET_FLAG_IGNORE_CERT_CN_INVALID to
your HttpOpenRequest call. Anyway, you should also install the
certificate through IE, not just click "accept" button that it shows
for an unrecognized certifciate.

Loading...