首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

inet控件 连续POST 的有关问题,求解

2012-12-15 
inet控件 连续POST 的问题,求解本帖最后由 ybbtng 于 2011-11-09 02:11:18 编辑inet 控件在一个过程里面可

inet控件 连续POST 的问题,求解
本帖最后由 ybbtng 于 2011-11-09 02:11:18 编辑 inet 控件在一个过程里面可以连续用Execute方法 POST 吗

例如
Private Sub 1_Click()
inet1 Execute "POST" 
inet1 Execute "POST" 

inet1 Execute "POST" 


end sub

[最优解释]

VERSION 5.00
Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
Begin VB.Form Form1
   BorderStyle     =   1  'Fixed Single
   ClientHeight    =   3060
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4035
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3060
   ScaleWidth      =   4035
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1
      Caption         =   "下载"
      Height          =   495
      Left            =   1440
      TabIndex        =   0
      Top             =   1320
      Width           =   1215
   End
   Begin InetCtlsObjects.Inet Inet1
      Left            =   -15
      Top             =   -15
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim ExeStr As String
Dim Done As Boolean
Private Sub cmd(cmdstr As String)
    Do
        If Inet1.StillExecuting = False Then Exit Do
    Loop
    ExeStr = cmdstr
    Done = False


    Debug.Print ExeStr; "="
    Inet1.Execute , ExeStr
    Do
        DoEvents
        If Done Then Exit Do
    Loop
End Sub
Public Sub ReadNewDat(dat As String)
    Inet1.URL = "ftp://192.168.1.123"
    Inet1.UserName = "username"
    Inet1.Password = "password"

    'cmd "PWD"
    'cmd "CD /data"
    'cmd "DIR"

    cmd "GET " + vox + ".dat " + App.Path + "" + dat + ".dat"

    cmd "QUIT"
End Sub

Private Sub Command1_Click()
    Command1.Enabled = False
    ReadNewDat ("20111109")
    Command1.Enabled = True
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim intFile As Integer
Dim vtData() As Byte
Dim str As String
'On Error GoTo ISCerr
    Debug.Print "State="; State,
    Select Case State
    Case 0
        Debug.Print "icNone"
    Case 1
        Debug.Print "icHostResolvingHost"
    Case 2
        Debug.Print "icHostResolved"
    Case 3
        Debug.Print "icConnecting"
    Case 4
        Debug.Print "icConnected"
    Case 5
        Debug.Print "icRequesting"
    Case 6
        Debug.Print "icRequestSent"
    Case 7
        Debug.Print "icReceivingResponse"
    Case 8
        Debug.Print "icResponseReceived"
        If Left(ExeStr, 2) = "CD" Then Done = True
    Case 9
        Debug.Print "icDisconnecting"
    Case 10
        Debug.Print "icDisconnected"
        Done = True
    Case 11
        Debug.Print "icError of [" + ExeStr + "]="; Inet1.ResponseInfo
        Done = True
    Case 12
        Debug.Print "icResponseCompleted----------------"
        Do
            str = Inet1.GetChunk(1024, icString)
            If LenB(str) = 0 Then Exit Do
            Debug.Print str


        Loop
        Done = True
    End Select
    Exit Sub
ISCerr:
    Resume Next
End Sub


[其他解释]
inet如果是异步工作那么多次post就会产生不可预计的后果.
如果是同步则可以多次post,每次产生指定的结果.
但inet性能不太好。有时还卡住。建议是使用httpserver组件。在VB中引入它就可以了。它也类似inet但更安全可靠。且可以自己写类来控制它。很好用

热点排行