Establishing SSL connection in Visual Basic 6.0

G

Garg

Hi,

I have a desktop application, written in VB 6.0. It transfers data to
a web-application through HTTP protocol.

The code is something like this:

Public Sub SendServerCommandUsingHTTPPost(strMessage As String,
lTimeout As Long)

Dim hInternetOpen As Long
Dim hInternetConnect As Long
Dim hHTTPOpenRequest As Long
Dim bRet As Long
Dim lBufLen As Long
Dim bSuccess As Boolean
Dim strTemp As String
Dim lpszPostData As String
Dim lPostDataLen As Long
Dim sHeader As String

'If the copy to clipboard flag is set, copy the transmit string to
the text clipboard
If copyTransmitToClipboard Then
Clipboard.Clear
Clipboard.SetText (strMessage)
End If

hInternetOpen = InternetOpen(APP_NAME,
INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&)
If hInternetOpen Then

bRet = InternetSetOption(hInternetOpen,
INTERNET_OPTION_CONNECT_TIMEOUT, lTimeout, 4)

hInternetConnect = InternetConnect(hInternetOpen,
ParseWebServer(MyConfig.EcommServerURL),
ParseWebServerPort(MyConfig.EcommServerURL), vbNullString, "HTTP/1.0",
INTERNET_SERVICE_HTTP, 0, 0)

If hInternetConnect Then

hHTTPOpenRequest = HttpOpenRequest(hInternetConnect,
"POST", ParseWebContext(MyConfig.EcommServerURL), "HTTP/1.0",
vbNullString, 0, INTERNET_FLAG_RELOAD, 0)

If hHTTPOpenRequest Then


sHeader = "Content-Type: application/x-www-form-
urlencoded" & vbCrLf
bRet = HttpAddRequestHeaders(hHTTPOpenRequest, sHeader,
Len(sHeader), HTTP_ADDREQ_FLAG_REPLACE Or HTTP_ADDREQ_FLAG_ADD)


strMessage = "BEG|WML.kimhayes|WMP.kimhayes|WMS.994042|WMD.
0x0200017982A00|WMC.WFLD103477|PSI.80249353|PSI.80372215|WMT.131901|
WMQ.005|WMT.131903|WMU.BX|WMT.131905|END"

lpszPostData = "fast2data=" & strMessage
lPostDataLen = Len(lpszPostData)
bRet = HttpSendRequest(hHTTPOpenRequest, vbNullString, 0,
lpszPostData, lPostDataLen)
-------------------------------------------------------------------------------------------------------------------------------------------------------

mvarEcommServerResponse = Space(1000)
bRet = InternetReadFile(hHTTPOpenRequest,
mvarEcommServerResponse, 1000, lBufLen)

---- Close internet handles... code removed...

End Sub





MY PROBLEM IS:
------------------------------
When i converted this code for enabling HTTPS connection, i made
changes at two places:
1. I changed the Port number from 80 to 443 in
"ParseWebServerPort(MyConfig.EcommServerURL)"

hInternetConnect = InternetConnect(hInternetOpen,
ParseWebServer(MyConfig.EcommServerURL),
ParseWebServerPort(MyConfig.EcommServerURL), vbNullString, "HTTP/1.0",
INTERNET_SERVICE_HTTP, 0, 0)

2. I used INTERNET_FLAG_SECURE ( &H800000 ) in place of
INTERNET_FLAG_RELOAD in the following line of code

hHTTPOpenRequest = HttpOpenRequest(hInternetConnect, "POST",
ParseWebContext(MyConfig.EcommServerURL), "HTTP/1.0", vbNullString, 0,
INTERNET_FLAG_RELOAD, 0)

Now when I debug my application, I find that the httpSendRequest
method returns a zero value for above changes. Whereas it returns 1
for the code written above, i.e in case of HTTP protocol.

Could someone please tell me if I am missing out some other code
change that I need to do in order to establish HTTPS connection. Any
thoughts are also welcome...

Thanks,
Shivani Garg
 
T

Tiago Teixeira

Hi,

I have a desktop application, written in VB 6.0. It transfers data to
a web-application through HTTP protocol.

The code is something like this:

Public Sub SendServerCommandUsingHTTPPost(strMessage As String,
lTimeout As Long)

   Dim hInternetOpen As Long
   Dim hInternetConnect As Long
   Dim hHTTPOpenRequest As Long
   Dim bRet As Long
   Dim lBufLen As Long
   Dim bSuccess As Boolean
   Dim strTemp As String
   Dim lpszPostData As String
   Dim lPostDataLen As Long
   Dim sHeader As String

   'If the copy to clipboard flag is set, copy the transmit string to
the text clipboard
   If copyTransmitToClipboard Then
      Clipboard.Clear
      Clipboard.SetText (strMessage)
   End If

    hInternetOpen = InternetOpen(APP_NAME,
INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&)
   If hInternetOpen Then

      bRet = InternetSetOption(hInternetOpen,
INTERNET_OPTION_CONNECT_TIMEOUT, lTimeout, 4)

          hInternetConnect = InternetConnect(hInternetOpen,
ParseWebServer(MyConfig.EcommServerURL),
ParseWebServerPort(MyConfig.EcommServerURL), vbNullString, "HTTP/1.0",
INTERNET_SERVICE_HTTP, 0, 0)

      If hInternetConnect Then

                 hHTTPOpenRequest = HttpOpenRequest(hInternetConnect,
"POST", ParseWebContext(MyConfig.EcommServerURL), "HTTP/1.0",
vbNullString, 0, INTERNET_FLAG_RELOAD, 0)

         If hHTTPOpenRequest Then

            sHeader = "Content-Type: application/x-www-form-
urlencoded" & vbCrLf
            bRet = HttpAddRequestHeaders(hHTTPOpenRequest, sHeader,
Len(sHeader), HTTP_ADDREQ_FLAG_REPLACE Or HTTP_ADDREQ_FLAG_ADD)

           strMessage = "BEG|WML.kimhayes|WMP.kimhayes|WMS.994042|WMD.
0x0200017982A00|WMC.WFLD103477|PSI.80249353|PSI.80372215|WMT.131901|
WMQ.005|WMT.131903|WMU.BX|WMT.131905|END"

            lpszPostData = "fast2data=" & strMessage
            lPostDataLen = Len(lpszPostData)
            bRet = HttpSendRequest(hHTTPOpenRequest, vbNullString, 0,
lpszPostData, lPostDataLen)
---------------------------------------------------------------------------­---------------------------------------------------------------------------­-

            mvarEcommServerResponse = Space(1000)
            bRet = InternetReadFile(hHTTPOpenRequest,
mvarEcommServerResponse, 1000, lBufLen)

           ---- Close internet handles... code removed...

End Sub

MY PROBLEM IS:
------------------------------
When i converted this code for enabling HTTPS connection, i made
changes at two places:
1. I changed the Port number from 80 to 443 in
"ParseWebServerPort(MyConfig.EcommServerURL)"

    hInternetConnect = InternetConnect(hInternetOpen,
ParseWebServer(MyConfig.EcommServerURL),
ParseWebServerPort(MyConfig.EcommServerURL), vbNullString, "HTTP/1.0",
INTERNET_SERVICE_HTTP, 0, 0)

2. I used INTERNET_FLAG_SECURE ( &H800000 ) in place of
INTERNET_FLAG_RELOAD in the following line of code

   hHTTPOpenRequest = HttpOpenRequest(hInternetConnect, "POST",
ParseWebContext(MyConfig.EcommServerURL), "HTTP/1.0", vbNullString, 0,
INTERNET_FLAG_RELOAD, 0)

Now when I debug my application, I find that the httpSendRequest
method returns a zero value for above changes. Whereas it returns 1
for the code written above, i.e in case of HTTP protocol.

Could someone please tell me if I am missing out some other code
change that I need to do in order to establish HTTPS connection. Any
thoughts are also welcome...

Thanks,
Shivani Garg

Hello,

I need some help like this. I need to conect a VB 6 program with a
HTTPS website. Someone knows how can I connect this?

Thanks
 

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

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top