Attribute VB_Name = "mod_InetAsync"

Private InetReceiver As String
Public InetMessage As String


Private Sub RequestData()

    Dim url As String
    Dim istate As Integer
    Dim tm1 As Date
    Dim postdata As String

    tm1 = Now
    
   
    postdata = ""
    postdata = postdata & "USER=" & myEmail
    
    InetReceiver = ""
    Call Inet1.Execute(ServAPI, "POST", postdata, "Content-Type: application/x-www-form-urlencoded " & vbCrLf)

    Do Until istate = icResponseCompleted
        Call Inet1_StateChanged(istate)
        DoEvents
        
        InetMessage = "connecting..." & DateDiff("s", tm1, Now)
        
        If (InetReceiver <> "") Then Exit Do
        
        If (DateDiff("s", tm1, Now) > 8) Then
            InetMessage = "Connection failed - try again"
            InetReceiver = "-2"
            Exit Sub
        End If
    Loop
    InetReceiver = Trim(InetReceiver)
    InetReceiver = Replace(InetReceiver, Chr(10), vbCrLf)
    
    If (InetReceiver <> "-2") Then
        InetMessage = InetReceiver
    Else
        InetMessage = "response error"
    End If

Exit Sub
    
End Sub



Private Sub Inet1_StateChanged(ByVal State As Integer)
    
    Dim var_data As Variant
    Dim str_data As String

    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
        InetReceiver = str_data
    End If
    
End Sub
