Link to home
Start Free TrialLog in
Avatar of pmud
pmud

asked on

POSTing with INET control to httpS web page

Hi,

I am using Inet control to do a POST to an http web page. this works perfectly. But when I changed the URL to be httpS , then the Inet control doesnt work. I think this is happening 'coz the SSL certificate on the server is not  a valid one or it has expired. But I want to know of a way for the Inet control to by pass any SSL certificate related errors. Below is the code I am using.

 Dim strURL As String
  strURL = "https://IP/clerical/activexio.cfm"
    '
     Dim strRequestHeader As String
    'This is the descriptive header for the HTML post
    strRequestHeader = "Content-Type: multipart/form-data; boundary=" & strHTMLBoundary

    'Prepare for posting
   
    AttachDate "Birth_Date", dteBirthDate, strInputData
    AttachString "First", LTrim$(arrPName(0)), strInputData
    AttachString "Last", LTrim$(arrPName(1)), strInputData
    CloseRequest strInputData


    On Error GoTo errHandler15:
    Inet1.Execute strURL, "POST", strInputData, strRequestHeader

    Do While Inet1.StillExecuting
           DoEvents
    Loop
 
'Get the response back from the server.
Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim var_data As Variant
Dim str_data As String

Dim arrResult() As Integer
    Debug.Print State
   
   If State = icConnecting Then  'state=3
        MsgBox "connecting"
    End If
     If State = icConnected Then   'state=4
        MsgBox "connecting"
    End If
     If State = icDisconnecting Then   'state=9
        MsgBox "DISconnecting"
    End If
     If State = icDisconnected Then   'state=10
        MsgBox "DISconnected"
    End If
   
    If State = icError Then  'state=11
         ' Get the first chunk.
        var_data = Inet1.GetChunk(1024, icString)
        str_data = str_data & var_data

        ' Get the rest of the chunks.
        Do
            DoEvents
            var_data = Inet1.GetChunk(1024, icString)
            If Len(var_data) = 0 Then Exit Do
            str_data = str_data & var_data    
        Loop
    End If

    If State = icResponseCompleted Then  ''---NEVER REACHES THIS STATE WITH HTTPS:
        'do something
    End If

Any help will be highly appreciated.

Thanks
Avatar of pmud
pmud

ASKER

Hi,

I figures the error message from the server. I get response as : "12045 client authorization not setup". this is because the SSL certificate is not valid. how can I bypass the error message so that Inet control ignores any such error message?

Thanks
add a on error resume next?
yea-just ignore the error...
in your errorHandler15 you can have code that bypass a specific error also if you do not want to use on error resume next, this can be done by checking the Err.Description against a certain string i guess.
Avatar of pmud

ASKER

Hi,

I am not good with error handlers. It will be really helpful, if you can post the code exactly on how to by pass this  "12045 client authorization not setup"   error. Below is my code.

Private function test ()
'some statements here

 On Error GoTo errHandler15:
    Inet1.Execute strURL, "POST", strInputData, strRequestHeader

    Do While Inet1.StillExecuting
           DoEvents
    Loop

    NoOfMatchedRecords = CInt(strRetValue(0))

    If NoOfMatchedRecords > 0 Then
       'go to the next sub Directory in the chosen drive
            n = m + 1
          RepeatLoop
       Exit Function
    ElseIf NoOfMatchedRecords = 0 Then  ' If not uploaded already, then get the matching records from the Db.
       CheckInDatabase
    End If
   
errHandler15:
  Debug.Print Err.Description
End Function


'Get the response back from the server.
Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim var_data As Variant
Dim str_data As String

 Debug.Print State
   
  Dim vtData As Variant ' Data variable
    If State = icError Then  'state=11
         vtData = Inet1.ResponseCode & ":" & Inet1.ResponseInfo   ' -- State is 11 when error is retuned.
    End If

    If State = icResponseCompleted Then
        ' Get the first chunk.
        var_data = Inet1.GetChunk(1024, icString)
        str_data = str_data & var_data

        ' Get the rest of the chunks.
        Do
            DoEvents
            var_data = Inet1.GetChunk(1024, icString)
            If Len(var_data) = 0 Then Exit Do
            str_data = str_data & var_data
        Loop

       'Do some more statements here.

    End If
End Sub

Thanks for your help.
which line does the error occur at?
Avatar of pmud

ASKER

Hi justchat1,

When the following line is executed, the control jumps to the Inet1_StateChanged event of the inet control.
 
  Inet1.Execute strURL, "POST", strInputData, strRequestHeader

 In that event, the state=11 (icError) is what returns the server reponse Error message which is ( "12045 client authorization not setup" ) .   Below is the code for this event.

'Get the response back from the server.
Private Sub Inet1_StateChanged(ByVal State As Integer)

Dim var_data As Variant
Dim str_data As String
   
  Dim vtData As Variant ' Data variable
    If State = icError Then  'state=11
         vtData = Inet1.ResponseCode & ":" & Inet1.ResponseInfo   ' -- State is 11 when error is retuned.
    End If

End Sub

Thanks for youe help.
ok, in the errorHandler15 section, add a line:

msgbox Err.Description

now see what desc it give for that error you want to bypass and then just use a if statement to bypass it?

If Err.Description = "THE DESC YOU GOT" then
    goto Pass
End if
ASKER CERTIFIED SOLUTION
Avatar of justchat_1
justchat_1

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 pmud

ASKER

Hi justchat 1,

I had already found that article, but even that is not helpful since it mentions that either the certificate needs to be valid or you have to install the certificate on each machine which runs the application. But some times a certificate might expire or may no longer be valid. But we want to application to still work... and installing on each machine cannot be possible.

Is there any other suggestion that anyone has? This is a serious issue for me. Is there no way that teh INet (internet transfer ) control can ignore the 12045 error and atill reach state 12?? If not, then is there any other control in VB 6.0 which has this capability?

Thanks for your help.
Avatar of pmud

ASKER

Hi,

I was trying to install teh digital certificate on my machine to see if that will even work. But as mentioned in the article, it says click the golden lock at the bottom of IE and then click install. But I cant see that golden lock! How to install the digital certificate on my machine?  

Thanks
Avatar of pmud

ASKER

Hi,

I got the lock and installed the certificate but even then the Inet control is showing the 12045 error. Any other ideas?

Thanks
You need to install the certificate and set it as trusted...
If IE stills prompts you to accept the certificate then it hasnt been installed and trusted correctly...
Avatar of pmud

ASKER

Hi justchat1,

I installed the certificate and added it to the trusted sites list but now i get server response back as "12038: HTTP TO HTTPS on redirect" . Why is this happening? Could iot be because the certificate name is not the same as the name of the site? Do both NEED to be the same?

Thanks.
Error Definition/description (by error code):
12038       ERROR_INTERNET_SEC_CERT_CN_INVALID
SSL certificate common name (host name field) is incorrect.
For example, if you entered http://www.server.com"  and the common name on the certificate says http://www.different.com"

Basically its an invalid certificate... this is a problem the owner of the web server should fix
I found your problem and told you what needs to be done to resolve it but I wasnt able to correct th eproblem...not sure what you want to do with points?