Majusri
asked on
VB Inet Control
Hi everyone, I'm new to VB world! I am using a simple Inet Control and the syntax is below
response = Inet1.OpenURL(URL, icString)
MsgBox (response)
but somehow it doesn't connect to the URL
Do I need to set up something or activate the control or something?
any idea?
thanks
response = Inet1.OpenURL(URL, icString)
MsgBox (response)
but somehow it doesn't connect to the URL
Do I need to set up something or activate the control or something?
any idea?
thanks
Majusri,
It takes a little time to establish the connection and return the contents of the page you are requesting. The loop will allow your program to wait for the page to be returned. You could also put code into the StateChanged event for the control. That would prevent you from using CPU cycles in a wait loop. The method you pick would depend on what you want to accomplish.
Dang123
It takes a little time to establish the connection and return the contents of the page you are requesting. The loop will allow your program to wait for the page to be returned. You could also put code into the StateChanged event for the control. That would prevent you from using CPU cycles in a wait loop. The method you pick would depend on what you want to accomplish.
Dang123
ASKER
well it not really working! I implement this peice of code
Do While Inet1.StillExecuting
DoEvents
Loop
but it giving me the error :
Gopher - Attribute not found
the error code is 12057
it seem like sometime it work and most of the time it given this error. Anyone know why?
Majusri
Do While Inet1.StillExecuting
DoEvents
Loop
but it giving me the error :
Gopher - Attribute not found
the error code is 12057
it seem like sometime it work and most of the time it given this error. Anyone know why?
Majusri
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
VERSION 5.00
Object = "{48E59290-9880-11CF-9754- 00AA00C009 08}#1.0#0" ; "MSINET.OCX"
Begin VB.Form uploadFile
Caption = "uploadForm"
ClientHeight = 6645
ClientLeft = 3435
ClientTop = 3030
ClientWidth = 11100
Icon = "uploadFile.frx":0000
ScaleHeight = 6645
ScaleWidth = 11100
Begin InetCtlsObjects.Inet Inet1
Left = 4080
Top = 2040
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
Protocol = 5
RemotePort = 443
URL = "https://"
End
Begin VB.CommandButton Command1
Caption = "upload now!"
Height = 495
Left = 3720
TabIndex = 0
Top = 1320
Width = 1215
End
End
Attribute VB_Name = "uploadFile"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
ListFile "F:/"
End Sub
Public Sub ListFile(ByVal DirName As String)
Dim filesys As Object
Dim txtStream As Object
Dim files
Dim fileName
Dim File
Dim strXML As String
Dim URL As String
Dim folder
Dim response As String
Dim fileLoad As String
Dim pass As String
On Error Resume Next
If (Dir$(DirName, vbDirectory) = "") Then Exit Sub
Set filesys = CreateObject("Scripting.Fi leSystemOb ject")
Set folder = filesys.GetFolder(DirName)
Set files = folder.files
If files.Count <> 0 Then
For Each File In files
Set f = filesys.GetFile(File)
Set txtStream = filesys.openTextFile(f)
setFileName = f.Name
If Not txtStream.AtEndOfStream Then
Do While Not txtStream.AtEndOfStream
strXML = strXML + txtStream.readline
Loop
End If
URL = "https://localhost/getXML.asp?filename=" & setFileName & "&" & "XML=" & strXML
Inet1.Cancel
Inet1.Protocol = icHTTPS
Inet1.AccessType = icDirect
Inet1.URL = URL
response = Inet1.OpenURL(URL, icString)
Loop
fileLoad = fileLoad + response
strXML = Clear
DoEvents
Next
End If
MsgBox (fileLoad)
End Sub
Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim status As String
Select Case State
Case icError
MsgBox (Inet1.ResponseCode & " " & Inet1.ResponseInfo)
End Select
End Sub
Object = "{48E59290-9880-11CF-9754-
Begin VB.Form uploadFile
Caption = "uploadForm"
ClientHeight = 6645
ClientLeft = 3435
ClientTop = 3030
ClientWidth = 11100
Icon = "uploadFile.frx":0000
ScaleHeight = 6645
ScaleWidth = 11100
Begin InetCtlsObjects.Inet Inet1
Left = 4080
Top = 2040
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
Protocol = 5
RemotePort = 443
URL = "https://"
End
Begin VB.CommandButton Command1
Caption = "upload now!"
Height = 495
Left = 3720
TabIndex = 0
Top = 1320
Width = 1215
End
End
Attribute VB_Name = "uploadFile"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
ListFile "F:/"
End Sub
Public Sub ListFile(ByVal DirName As String)
Dim filesys As Object
Dim txtStream As Object
Dim files
Dim fileName
Dim File
Dim strXML As String
Dim URL As String
Dim folder
Dim response As String
Dim fileLoad As String
Dim pass As String
On Error Resume Next
If (Dir$(DirName, vbDirectory) = "") Then Exit Sub
Set filesys = CreateObject("Scripting.Fi
Set folder = filesys.GetFolder(DirName)
Set files = folder.files
If files.Count <> 0 Then
For Each File In files
Set f = filesys.GetFile(File)
Set txtStream = filesys.openTextFile(f)
setFileName = f.Name
If Not txtStream.AtEndOfStream Then
Do While Not txtStream.AtEndOfStream
strXML = strXML + txtStream.readline
Loop
End If
URL = "https://localhost/getXML.asp?filename=" & setFileName & "&" & "XML=" & strXML
Inet1.Cancel
Inet1.Protocol = icHTTPS
Inet1.AccessType = icDirect
Inet1.URL = URL
response = Inet1.OpenURL(URL, icString)
Loop
fileLoad = fileLoad + response
strXML = Clear
DoEvents
Next
End If
MsgBox (fileLoad)
End Sub
Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim status As String
Select Case State
Case icError
MsgBox (Inet1.ResponseCode & " " & Inet1.ResponseInfo)
End Select
End Sub
ASKER
ignore the Loop after the Inet1.OpenURL
ASKER
does anyone know why did I get this error
error code: 12057
error message: Gopher - Attribute not found
error code: 12057
error message: Gopher - Attribute not found
Majusri,
Were you able to solve the 12057 error? I was still looking at the code you posted above. I don't have a server I can test it against, so it was taking a bit longer.
By the way, if you have line breaks in your XML files, I think you may have a problem with them since you are passing them in your URL. Also since a URL has a maximum length of 2,083 I was also considering that if your files are large it may be causing problems also.
Dang123
Were you able to solve the 12057 error? I was still looking at the code you posted above. I don't have a server I can test it against, so it was taking a bit longer.
By the way, if you have line breaks in your XML files, I think you may have a problem with them since you are passing them in your URL. Also since a URL has a maximum length of 2,083 I was also considering that if your files are large it may be causing problems also.
Dang123
ASKER
Thanks Dang123!
The problem being is the Revocation List(SSL) is not available therefore the Inet Control throws that error. I have clue why is that but I have tried a different server and it working quite well. So thank alot for your help.
Majusri - VanThu
The problem being is the Revocation List(SSL) is not available therefore the Inet Control throws that error. I have clue why is that but I have tried a different server and it working quite well. So thank alot for your help.
Majusri - VanThu
Hi,
Could I ask how did you fix the issue? I have the same problem in a similar environment
Error 11 Gopher Attribute not found
Many thanks
Antonio
Could I ask how did you fix the issue? I have the same problem in a similar environment
Error 11 Gopher Attribute not found
Many thanks
Antonio
This is my code:
VERSION 5.00
Object = "{48E59290-9880-11CF-9754- 00AA00C009 08}#1.0#0" ; "MSINET.OCX"
Begin VB.Form frmRecu
BorderStyle = 1 'Fixed Single
ClientHeight = 615
ClientLeft = 15
ClientTop = 15
ClientWidth = 1200
ControlBox = 0 'False
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 615
ScaleWidth = 1200
StartUpPosition = 3 'Windows Default
Begin VB.Timer timMaxEspera
Left = 630
Top = 0
End
Begin InetCtlsObjects.Inet InetRecPub
Left = 45
Top = 0
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
End
End
Attribute VB_Name = "frmRecu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' DTA (RT)
Private blnDatosRecibido As Boolean
Private strDatosEnt As String
Private mlngInterval As Long
Private Sub ActivaTemporizador()
On Error GoTo errActivaTemporizador
If mlngInterval <> 0 Then timMaxEspera.Enabled = True
errActivaTemporizador:
If Err.Number <> 0 Then
strMsgError = "Error al inicializadar el temporizador"
End If
End Sub
Public Property Let MaxTmpEspera(ByVal lngMaxTmp As Long)
On Error GoTo errMaxTmpEspera
lngMaxTmp = lngMaxTmp * 1000
If lngMaxTmp < 1 And lngMaxTmp > 60000 Then
strMsgError = "[ComPetHTTP:frmRecu:MaxTmpEspera] Se estableció un tiempo de espera incorrecto " & lngMaxTmp
mlngInterval = 0
Else
timMaxEspera.Interval = lngMaxTmp
mlngInterval = lngMaxTmp
End If
errMaxTmpEspera:
If Err.Number Then
strMsgError = "Error al establecer el tiempo máximo de espera " & lngMaxTmp
End If
End Property
Public Function RecContURL(ByRef stCont As String, ByVal stUrl As String, _
Optional ByVal stPuerto As String) As Boolean
On Error GoTo errRecContURL
With InetRecPub
' Le estoy estableciendo el tiempo maximo de espera
.RequestTimeout = 15
.Protocol = icHTTP
If stPuerto <> "" Then .RemotePort = stPuerto
.URL = stUrl
stCont = .OpenURL()
End With
RecContURL = True
errRecContURL:
If Err.Number <> 0 Then
stCont = Err.Description
RecContURL = False
End If
End Function
Public Function SendDataUrl(ByRef strDatResp As String, ByRef arrDatos() As String, _
ByVal strURL As String, ByVal strPuerto As String) As Boolean
Dim strDAtos As String
Dim lngCampo As Long
On Error GoTo errRecContURL
For lngCampo = 0 To UBound(arrDatos) Step 2
If strDAtos <> "" Then strDAtos = strDAtos & "&"
strDAtos = strDAtos & arrDatos(lngCampo) & "=" & arrDatos(lngCampo + 1)
Next lngCampo
With InetRecPub
.RequestTimeout = 15
.Protocol = icHTTPS 'icHTTP
If strPuerto <> "" Then .RemotePort = strPuerto
blnDatosRecibido = False
.Execute strURL, "POST", strDAtos, "Content-Type: application/x-www-form-url encoded"
ActivaTemporizador
Do While Not blnDatosRecibido And strMsgError = ""
DoEvents
Loop
If blnDatosRecibido And strMsgError = "" Then
strDatResp = strDatosEnt
SendDataUrl = True
End If
End With
errRecContURL:
If Err.Number <> 0 Then
If strMsgError = "" Then
strMsgError = "[ComPetHttp: SendDataUrl] Error(" & Err.Description & ")" & _
"Cadena:" & Join(arrDatos, "#$#")
End If
SendDataUrl = False
End If
End Function
Private Sub Form_Load()
blnFormLoad = True
mlngInterval = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
blnFormLoad = False
End Sub
Private Sub InetRecPub_StateChanged(By Val State As Integer)
' Cuando termine correctamente, recuperaré los datos devueltos por la página
Dim strBloqDat As String
On Error GoTo errInetRecPub_StateChanged
Select Case State
Case icResponseCompleted
strBloqDat = InetRecPub.GetChunk(1024, icString)
Do While strBloqDat <> ""
strDatosEnt = strDatosEnt & strBloqDat
strBloqDat = InetRecPub.GetChunk(1024, icString)
Loop
blnDatosRecibido = True
timMaxEspera.Enabled = False
Case icError
strMsgError = "No se pudo conectar con el servidor especificado " & InetRecPub.ResponseInfo
End Select
errInetRecPub_StateChanged :
If Err.Number <> 0 Then
If strMsgError = "" Then strMsgError = "Error en InetRecPub_StateChanged(" & _
Err.Description & ")"
End If
End Sub
Private Sub timMaxEspera_Timer()
strMsgError = "Agotado el tiempo maximo de espera"
lngErr = 10001
timMaxEspera.Enabled = False
End Sub
VERSION 5.00
Object = "{48E59290-9880-11CF-9754-
Begin VB.Form frmRecu
BorderStyle = 1 'Fixed Single
ClientHeight = 615
ClientLeft = 15
ClientTop = 15
ClientWidth = 1200
ControlBox = 0 'False
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 615
ScaleWidth = 1200
StartUpPosition = 3 'Windows Default
Begin VB.Timer timMaxEspera
Left = 630
Top = 0
End
Begin InetCtlsObjects.Inet InetRecPub
Left = 45
Top = 0
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
End
End
Attribute VB_Name = "frmRecu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' DTA (RT)
Private blnDatosRecibido As Boolean
Private strDatosEnt As String
Private mlngInterval As Long
Private Sub ActivaTemporizador()
On Error GoTo errActivaTemporizador
If mlngInterval <> 0 Then timMaxEspera.Enabled = True
errActivaTemporizador:
If Err.Number <> 0 Then
strMsgError = "Error al inicializadar el temporizador"
End If
End Sub
Public Property Let MaxTmpEspera(ByVal lngMaxTmp As Long)
On Error GoTo errMaxTmpEspera
lngMaxTmp = lngMaxTmp * 1000
If lngMaxTmp < 1 And lngMaxTmp > 60000 Then
strMsgError = "[ComPetHTTP:frmRecu:MaxTmpEspera] Se estableció un tiempo de espera incorrecto " & lngMaxTmp
mlngInterval = 0
Else
timMaxEspera.Interval = lngMaxTmp
mlngInterval = lngMaxTmp
End If
errMaxTmpEspera:
If Err.Number Then
strMsgError = "Error al establecer el tiempo máximo de espera " & lngMaxTmp
End If
End Property
Public Function RecContURL(ByRef stCont As String, ByVal stUrl As String, _
Optional ByVal stPuerto As String) As Boolean
On Error GoTo errRecContURL
With InetRecPub
' Le estoy estableciendo el tiempo maximo de espera
.RequestTimeout = 15
.Protocol = icHTTP
If stPuerto <> "" Then .RemotePort = stPuerto
.URL = stUrl
stCont = .OpenURL()
End With
RecContURL = True
errRecContURL:
If Err.Number <> 0 Then
stCont = Err.Description
RecContURL = False
End If
End Function
Public Function SendDataUrl(ByRef strDatResp As String, ByRef arrDatos() As String, _
ByVal strURL As String, ByVal strPuerto As String) As Boolean
Dim strDAtos As String
Dim lngCampo As Long
On Error GoTo errRecContURL
For lngCampo = 0 To UBound(arrDatos) Step 2
If strDAtos <> "" Then strDAtos = strDAtos & "&"
strDAtos = strDAtos & arrDatos(lngCampo) & "=" & arrDatos(lngCampo + 1)
Next lngCampo
With InetRecPub
.RequestTimeout = 15
.Protocol = icHTTPS 'icHTTP
If strPuerto <> "" Then .RemotePort = strPuerto
blnDatosRecibido = False
.Execute strURL, "POST", strDAtos, "Content-Type: application/x-www-form-url
ActivaTemporizador
Do While Not blnDatosRecibido And strMsgError = ""
DoEvents
Loop
If blnDatosRecibido And strMsgError = "" Then
strDatResp = strDatosEnt
SendDataUrl = True
End If
End With
errRecContURL:
If Err.Number <> 0 Then
If strMsgError = "" Then
strMsgError = "[ComPetHttp: SendDataUrl] Error(" & Err.Description & ")" & _
"Cadena:" & Join(arrDatos, "#$#")
End If
SendDataUrl = False
End If
End Function
Private Sub Form_Load()
blnFormLoad = True
mlngInterval = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
blnFormLoad = False
End Sub
Private Sub InetRecPub_StateChanged(By
' Cuando termine correctamente, recuperaré los datos devueltos por la página
Dim strBloqDat As String
On Error GoTo errInetRecPub_StateChanged
Select Case State
Case icResponseCompleted
strBloqDat = InetRecPub.GetChunk(1024, icString)
Do While strBloqDat <> ""
strDatosEnt = strDatosEnt & strBloqDat
strBloqDat = InetRecPub.GetChunk(1024, icString)
Loop
blnDatosRecibido = True
timMaxEspera.Enabled = False
Case icError
strMsgError = "No se pudo conectar con el servidor especificado " & InetRecPub.ResponseInfo
End Select
errInetRecPub_StateChanged
If Err.Number <> 0 Then
If strMsgError = "" Then strMsgError = "Error en InetRecPub_StateChanged(" & _
Err.Description & ")"
End If
End Sub
Private Sub timMaxEspera_Timer()
strMsgError = "Agotado el tiempo maximo de espera"
lngErr = 10001
timMaxEspera.Enabled = False
End Sub
response = Inet1.OpenURL(URL, icString)
Do While Inet1.StillExecuting
DoEvents
Loop
MsgBox (response)
Dang123