fb:porticula NoPaste
TSNEX_HTTP.bi
Uploader: | ThePuppetMaster |
Datum/Zeit: | 21.01.2008 21:21:02 |
'#####################################################################################################
'#####################################################################################################
' TSNE_V2 - TCP Socket Networking [Eventing] Version: 2
' Erweiterungs-Bibliothek
'#####################################################################################################
'#####################################################################################################
' 2008 By.: /_\ DeltaLab's - Deutschland
' Autor: Martin Wiemann
'#####################################################################################################
'##############################################################################################################
#include once "TSNE_V2.bi"
#include once "TSNEX_helper.bi"
'##############################################################################################################
Dim Shared TSNEX_HTTP as UInteger
Dim Shared TSNEX_HTTP_DataRX as String
Dim Shared TSNEX_HTTP_DataTX as String
'##############################################################################################################
Declare Function TSNEX_HTTP_Get (V_URL as String, ByRef B_Data as String, ByRef B_ReturnCode as Long = 0, V_UserAgent as String = "TSNE_Extension", V_RefererURL as String = "", V_ProxyHost as String = "", V_ProxyPort as UShort = 0) as Long
'##############################################################################################################
Sub TSNE_HTTP_Connected(ByVal V_TSNEID as UInteger)
TSNE_Data_Send(V_TSNEID, TSNEX_HTTP_DataTX)
End Sub
'--------------------------------------------------------------------------------------------------------------
Sub TSNE_HTTP_NewData(ByVal V_TSNEID as UInteger, ByRef V_Data as String)
TSNEX_HTTP_DataRX += V_Data
End Sub
'##############################################################################################################
Function TSNEX_HTTP_Get(V_URL as String, ByRef B_Data as String, ByRef B_ReturnCode as Long = 0, V_UserAgent as String = "TSNE_Extension", V_RefererURL as String = "", V_ProxyHost as String = "", V_ProxyPort as UShort = 0) as Long
Dim BV as Long
Dim XProt as String
Dim XHost as String
Dim XPort as UShort
Dim XPath as String
Dim XFile as String
Dim XType as String
Dim XUser as String
Dim XPass as String
Dim XFBCRLF as String = Chr(13, 10)
BV = URL_Split(V_URL, XProt, XHost, XPort, XPath, XFile, XType, XUser, XPass)
If BV <> 0 Then Return BV
If lcase(XProt) <> "http" then Return 2
If XPath = "" Then XPath = "/"
If XType <> "" Then XType "." & XType
If V_ProxyHost <> "" Then
If V_ProxyPort <= 0 Then Return 5
If XUser <> "" Then
If XPass <> "" Then XUser = ":" & XPass
XHost = XUser & "@" & XHost
End If
If XPort > 0 Then XHost += ":" & Str(XPort)
TSNEX_HTTP_DataTX = "GET HTTP://" & XHost & XPath & XFile & XType & " HTTP/1.0" & XFBCRLF
Else
TSNEX_HTTP_DataTX = "GET " & XPath & XFile & XType & " HTTP/1.1" & XFBCRLF
If XUser <> "" Then
If XPass <> "" Then
TSNEX_HTTP_DataTX += "Authorization: Basic " & Base64_Encode(XUser) & XFBCRLF
Else: TSNEX_HTTP_DataTX += "Authorization: Basic " & Base64_Encode(XUser & ":" & XPass) & XFBCRLF
End If
End if
End If
TSNEX_HTTP_DataTX += "Host: " & XHost & XFBCRLF
TSNEX_HTTP_DataTX += "User-Agent: " & V_UserAgent & XFBCRLF
If V_RefererURL <> "" Then TSNEX_HTTP_DataTX += "Referer: " & V_RefererURL & XFBCRLF
If V_ProxyHost <> "" Then
XHost = V_ProxyHost
XPort = V_ProxyPort
TSNEX_HTTP_DataTX += "Proxy-Connection: close" & XFBCRLF
Else: TSNEX_HTTP_DataTX += "Connection: close" & XFBCRLF
End If
If XPort = 0 Then XPort = 80
TSNEX_HTTP_DataTX += XFBCRLF
TSNEX_HTTP_DataRX = ""
BV = TSNE_Create_Client(TSNEX_HTTP, XHost, XPort, 0, @TSNE_HTTP_Connected, @TSNE_HTTP_NewData)
If BV < 0 Then Return BV
TSNE_WaitClose(TSNEX_HTTP)
If TSNEX_HTTP_DataRX = "" Then Return 3
Dim XHead as String
Dim X as UInteger
X = InStr(1, TSNEX_HTTP_DataRX, XFBCRLF & XFBCRLF)
If X <= 0 Then Return 4
XHead = Mid(TSNEX_HTTP_DataRX, 1, X - 1)
B_Data = Mid(TSNEX_HTTP_DataRX, X + 4)
X = InStr(1, XHead, XFBCRLF)
If X <= 0 Then Return 100
XHead = Mid(XHead, 1, X - 1)
X = InStr(1, XHead, " ")
If X <= 0 Then Return 100
XHead = Mid(XHead, X + 1)
X = InStr(1, XHead, " ")
If X > 0 Then
B_ReturnCode = Val(Mid(XHead, 1, X - 1))
Else: B_ReturnCode = Val(XHead)
End If
Return 0
End Function