[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7344
  • Last Modified:

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

0
Kedarj7
Asked:
Kedarj7
1 Solution
 
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now