Link to home
Start Free TrialLog in
Avatar of Kedarj7
Kedarj7

asked on

How do I connect to https site using Inet control in VB6?

I have used folowing vb6 code to connect https site using Inet control and sent parametrs in "POST" method and capture response from secured site either Success or Fail.
But the Inet control is throwing error (12029 Cannot connect). I am using proxy to connect the Internet. The can can be opened in browser.

Other Info
OS - Windows 2000 server with service pack 4.0

''Code Snippet
Dim strURL As String
Dim strPostData As String
Dim strHeader As String
''Proxy info
Inet1.AccessType = icNamedProxy
Inet1.Proxy = "10.x.xx.xx"
Inet1.UserName = "xxxxxx"
Inet1.Password = "xxxxxx"
 
''Input data pipe(|) seperated
strPostData = "InputParam=0100|abcdef|xyz|xxx|"
strURL = "https://www.<sitename>/servlets/TransReq"
strHeader = "Content-Type: application/x-www-form-urlencoded"
 
Inet1.Execute strURL, "POST", strPostData, strHeader
 
Do While Inet1.StillExecuting
   DoEvents
Loop
 
I am getting following error in Inet1_StateChanged event
12029 Cannot connect
 
Also getting blank response from Inet1.GetChunk (1024, icString)

Open in new window

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

can you try to add this line:




Inet1.Protocol = icHTTPS

Open in new window

Avatar of Kedarj7
Kedarj7

ASKER

Yes I had done that but the result was same.
How To Use the Proxy Property in the Internet Transfer Control
http://support.microsoft.com/default.aspx/kb/171379
I would try:

Inet2.Proxy = "http://10.x.xx.xx:80"

or

Inet2.Proxy = "https://10.x.xx.xx:80"

If 80 is the proxy port.  
Avatar of Kedarj7

ASKER

I will try the same and let u know. Another thing I'd like to share with you is that we have installed SSL certificate on our server. In IIS it shows "OK" also. Its a test certificate for 7 days. Does it affect the connectivity?
It's required for SSL, so it shouldn't.  If there's a problem with the certificate that should raise a different kind of error.
Avatar of Kedarj7

ASKER

https://10.x.xx.xx:80 is also not working. Giving the same error (12029 Cannot connect
)
Avatar of Kedarj7

ASKER

Pls provide me alternate solution for the same. Since I stucked with Inet control error I could not do the further coding and TAT for coding is alrady over.
Try adding a reference to Microsoft WinHTTP Services 5.1 then you can try code like this.  It will automatically pick up your proxy if you have saved it for Internet Explorer settings if they are set correctly.  Also, you should URL encode your data properly:
Option Explicit
 
Private Sub Command1_Click()
    Dim http As WinHttpRequest
 
    Dim strURL As String
    Dim strPostData As String
    Dim strHeader As String
    Dim strResponse As String
    
    ''Input data pipe(|) seperated
    strPostData = "InputParam=" & fURLEncode("0100|abcdef|xyz|xxx|")
    strURL = "https://www.<sitename>/servlets/TransReq"
 
 
    Set http = New WinHttpRequest
    http.Open "POST", strURL, False
    
    http.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    http.Send strPostData
    
    
    strResponse = http.ResponseText
    
End Sub
Public Function fURLEncode(strToEncode As String) As String
    Dim strTemp As String
    Dim lngLen As Long
    Dim intASC As Integer
    Dim i As Long
 
    lngLen = Len(strToEncode)
 
    For i = 1 To lngLen
        intASC = Asc(Mid$(strToEncode, i, 1))
        'Is the character in the list of valid chars?  Use alphanumerics only to be very very safe.
        If InStr(1, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", Chr(intASC)) Then  '$-_.!*'(),
            strTemp = strTemp & Chr(intASC)
        Else
            If intASC < 16 Then
                strTemp = strTemp & "%0" & Hex(intASC)
            Else
                strTemp = strTemp & "%" & Hex(intASC)
            End If
        End If
    Next i
    fURLEncode = strTemp
 
End Function

Open in new window

Avatar of Kedarj7

ASKER

Thanks Paul. I'll test the same and let u know
Avatar of Kedarj7

ASKER

Hi Paul. It's working where proxy is not available (direct internet) but on my test server proxy is enabled. I need the above code to be worked in proxy enabled environment. I tried to test with "SetCredentials" method but it didn't help me.  Pls suggest
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kedarj7

ASKER

Thanks Paul. The earlier code given by you is working fine. I have removed proxy from my test machine. Once again Thanks!!
good, nice elegant solution, thanks!