94 lines
1.2 KiB
Text
94 lines
1.2 KiB
Text
' Gambas class file
|
|
|
|
Public Http As HttpClient
|
|
Private Buffer As String
|
|
Public Mode As Boolean
|
|
|
|
Event GotData(Data As String)
|
|
|
|
Event GotError()
|
|
|
|
Public Sub Http_Read()
|
|
|
|
Dim sCad As String
|
|
|
|
If Mode = False Then Return
|
|
|
|
If Lof(Http) Then
|
|
Try Read #Http, sCad, Lof(Http)
|
|
If Not Error Then Buffer = Buffer & sCad
|
|
End If
|
|
|
|
End
|
|
|
|
Public Sub Http_Finished()
|
|
|
|
Dim sCad As String
|
|
|
|
If Mode = False Then Return
|
|
|
|
If Lof(Http) Then
|
|
Try Read #Http, sCad, Lof(Http)
|
|
If Not Error Then Buffer = Buffer & sCad
|
|
End If
|
|
|
|
Raise GotData(Buffer)
|
|
|
|
|
|
End
|
|
|
|
Public Sub Http_Error()
|
|
|
|
If Mode = False Then Return
|
|
|
|
Try Close #Http
|
|
|
|
Raise GotError()
|
|
|
|
End
|
|
|
|
|
|
|
|
Public Function PostData(Data As String) As String
|
|
|
|
Dim sCad As String
|
|
|
|
Buffer = ""
|
|
sCad = ""
|
|
|
|
Http.Async = Mode
|
|
Http.Post("text/xml", Data)
|
|
|
|
If Mode = False Then
|
|
|
|
Do While Http.Status > 0
|
|
|
|
'Wait 0.001
|
|
Wait 0.01
|
|
|
|
Loop
|
|
|
|
If Http.Status < 0 Then Return ""
|
|
If Http.Code <> 200 Then Return ""
|
|
|
|
If Lof(Http) Then
|
|
|
|
Read #Http, sCad, Lof(Http)
|
|
|
|
End If
|
|
|
|
sCad = Trim(sCad)
|
|
Return sCad
|
|
|
|
End If
|
|
|
|
End
|
|
|
|
|
|
Public Sub _new(sUrl As String)
|
|
|
|
Http = New HttpClient As "Http"
|
|
|
|
Http.URL = sUrl
|
|
|
|
End
|