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

Kedarj7Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
can you try to add this line:




Inet1.Protocol = icHTTPS

Open in new window

0
Kedarj7Author Commented:
Yes I had done that but the result was same.
0
PaulHewsCommented:
How To Use the Proxy Property in the Internet Transfer Control
http://support.microsoft.com/default.aspx/kb/171379
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

PaulHewsCommented:
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.  
0
Kedarj7Author Commented:
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?
0
PaulHewsCommented:
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.
0
Kedarj7Author Commented:
https://10.x.xx.xx:80 is also not working. Giving the same error (12029 Cannot connect
)
0
Kedarj7Author Commented:
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.
0
PaulHewsCommented:
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

0
Kedarj7Author Commented:
Thanks Paul. I'll test the same and let u know
0
Kedarj7Author Commented:
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
0
PaulHewsCommented:
Try this:
Option Explicit
 
Private Sub Command1_Click()
 
    Const HTTPREQUEST_PROXYSETTING_PROXY = 2
    Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
    Const HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1
    Dim WinHttpReq 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"
 
    Dim bDone As Boolean
    Dim intAttempts As Integer
    
    Set WinHttpReq = New WinHttpRequest
    
    'Assemble an HTTP request.
    Do While bDone = False And intAttempts < 3
         WinHttpReq.Open "POST", strURL, False
         WinHttpReq.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
 
         WinHttpReq.send  strPostData
         
         Select Case WinHttpReq.Status
         
         Case 407
            'Enter appropriate values for proxy and bypass
            WinHttpReq.setProxy HTTPREQUEST_PROXYSETTING_PROXY, "http://proxyaddress:8080", "bypass list"
            'Set the user name and password.
         
            WinHttpReq.SetCredentials "ProxyUserName", "ProxyPassword", _
                HTTPREQUEST_SETCREDENTIALS_FOR_PROXY
        
        Case 200
         
            Text1.Text = WinHttpReq.responseText
            bDone = True
         End Select
         intAttempts = intAttempts + 1
    Loop
 
 
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kedarj7Author Commented:
Thanks Paul. The earlier code given by you is working fine. I have removed proxy from my test machine. Once again Thanks!!
0
cool12399Commented:
good, nice elegant solution, thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.