Solved

POSTing with INET control to httpS web page

Posted on 2006-07-07
20
1,192 Views
Last Modified: 2013-11-13
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
0
Comment
Question by:pmud
  • 7
  • 7
  • 3
20 Comments
 

Author Comment

by:pmud
ID: 17063118
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
0
 
LVL 10

Expert Comment

by:sakuya_su
ID: 17063197
add a on error resume next?
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17063199
yea-just ignore the error...
0
 
LVL 10

Expert Comment

by:sakuya_su
ID: 17063207
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.
0
 

Author Comment

by:pmud
ID: 17065288
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.
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17065328
which line does the error occur at?
0
 

Author Comment

by:pmud
ID: 17065487
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.
0
 
LVL 10

Expert Comment

by:sakuya_su
ID: 17066049
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
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 9

Accepted Solution

by:
justchat_1 earned 500 total points
ID: 17066113
By error number is probably better but that's how you would do it...

However, I just read over your last comment;

The error returned is winsock going into an error state not the server returning an error message.

Ignoring the error wont work in this case, by design winsock will not connect to a server without a certificate.  A little Google search found this article:
http://www.xtremevbtalk.com/showthread.php?t=94240

It shows a workaround which involves installing the invalid certificate...sorry I didn't catch this earlier
0
 

Author Comment

by:pmud
ID: 17072920
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.
0
 

Author Comment

by:pmud
ID: 17073138
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
0
 

Author Comment

by:pmud
ID: 17073280
Hi,

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

Thanks
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17075804
You need to install the certificate and set it as trusted...
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17075807
If IE stills prompts you to accept the certificate then it hasnt been installed and trusted correctly...
0
 

Author Comment

by:pmud
ID: 17076305
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.
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17077062
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
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17291813
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?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now