CedZbir
Nombre de messages : 9 Age : 39 Localisation : Derrière le maitre Date d'inscription : 20/03/2007
| Sujet: Moteur HTTP Mar 20 Mar - 19:59 | |
| Moteur HTTP (ne gère pas le GZIP) vb.net - Code:
-
Imports System Imports System.Text Imports System.IO Imports System.Net Imports System.Net.Sockets Imports Microsoft.VisualBasic
Module ModSocket
Private pvStrHTTPServer As String Private pvStrHTTPPort As Integer Private pvStrHTTPRequest As String
Private pvStrHTTPAnswer As String Private pvStrHTTPData As String
Property StrHTTPServer() As String Get Return pvStrHTTPServer End Get Set(ByVal Value As String) pvStrHTTPServer = Value End Set End Property
Property StrHTTPPort() As Integer Get Return pvStrHTTPPort End Get Set(ByVal Value As Integer) pvStrHTTPPort = Value End Set End Property
Property StrHTTPRequest() As String Get Return pvStrHTTPRequest End Get Set(ByVal Value As String) pvStrHTTPRequest = Value End Set End Property
ReadOnly Property StrHTTPData() As String Get Return pvStrHTTPData End Get End Property
ReadOnly Property StrHTTPAnswer() As String Get Return pvStrHTTPAnswer End Get End Property
Private Function ConnectSocket() As Socket Dim s As Socket = Nothing Dim hostEntry As IPHostEntry = Nothing
' Get host related information. hostEntry = Dns.GetHostEntry(pvStrHTTPServer)
' Loop through the AddressList to obtain the supported AddressFamily. This is to avoid ' an exception that occurs when the host host IP Address is not compatible with the address family ' (typical in the IPv6 case). Dim address As IPAddress
For Each address In hostEntry.AddressList Dim endPoint As New IPEndPoint(address, pvStrHTTPPort) Dim tempSocket As New Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
tempSocket.Connect(endPoint)
If tempSocket.Connected Then s = tempSocket Exit For End If
Next address
Return s End Function
' This method requests the home page content for the specified server.
Private Function SocketSendReceive() As String 'Set up variables and String to write to the server. Dim ascii As Encoding = Encoding.Default Dim bytesSent As [Byte]() = ascii.GetBytes(pvStrHTTPRequest) Dim bytesReceived(255) As [Byte]
' Create a socket connection with the specified server and port. Dim s As Socket = ConnectSocket()
If s Is Nothing Then Return "Connection failed" End If ' Send request to the server. s.Send(bytesSent, bytesSent.Length, 0)
' Receive the server home page content. Dim bytes As Int32
' Read the first 256 bytes. Dim page As String = "" ' The following will block until the page is transmitted. Do bytes = s.Receive(bytesReceived, bytesReceived.Length, 0) 'page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes) page = page + Encoding.Default.GetString(bytesReceived, 0, bytes) Loop While bytes > 0
Return page End Function
Public Function MakeHTTPRequest(ByVal Action As Integer, ByVal Host As String, ByVal Chemin As String, ByVal Version As String, ByVal Parametres As String, ByVal Requete As String, ByVal UserAgent As String) As String Dim str_entete_http As String
'---------------------------------------------------------- If Action = 1 Then str_entete_http = "GET " ElseIf Action = 2 Then str_entete_http = "POST " Else MessageBox.Show("Erreur MakeHTTPRequest") Return vbNullString Exit Function End If
str_entete_http = str_entete_http + "/" & Chemin
If Action = 1 Then str_entete_http = str_entete_http + IIf(Parametres = vbNullString, vbNullString, "?" & Parametres) End If
str_entete_http = str_entete_http + " " + Version & ControlChars.CrLf
'---------------------------------------------------------- str_entete_http = str_entete_http + "User-Agent: " + UserAgent & ControlChars.CrLf str_entete_http = str_entete_http + "Host: " & Host + ControlChars.CrLf '---------------------------------------------------------- str_entete_http = str_entete_http + Requete & ControlChars.CrLf
'---------------------------------------------------------- If Action = 2 Then str_entete_http = str_entete_http + "Content-Length: " + Len(Parametres).ToString + ControlChars.CrLf + ControlChars.CrLf + Parametres End If
'---------------------------------------------------------- str_entete_http = str_entete_http + ControlChars.CrLf + ControlChars.CrLf Return str_entete_http End Function
Public Function ExecuteHTTPRequest() As String Dim res As String Dim a As Integer
res = SocketSendReceive()
a = InStr(res, ControlChars.CrLf + ControlChars.CrLf)
pvStrHTTPAnswer = Left(res, a) pvStrHTTPData = Right(res, Len(res) - (a + Len(ControlChars.CrLf + ControlChars.CrLf) - 1))
Return res End Function
Public Sub SetHTTPReferences(Optional ByVal server As String = "", Optional ByVal port As Integer = 0, Optional ByVal request As String = "") If server <> vbNullString Then pvStrHTTPServer = server If port <> 0 Then pvStrHTTPPort = port If request <> vbNullString Then pvStrHTTPRequest = request End Sub
End Module Désolé j'ai pas d'écrits en français. | |
|
Kapock Sans Rang Spécial :D
Nombre de messages : 55 Age : 29 Localisation : Belgique Date d'inscription : 19/03/2007
| Sujet: Re: Moteur HTTP Mar 20 Mar - 23:11 | |
| | |
|
Johaaann Master of Sbires
Nombre de messages : 102 Age : 38 Localisation : Bien au-dessus de toi Date d'inscription : 19/03/2007
| Sujet: Re: Moteur HTTP Mar 20 Mar - 23:25 | |
| | |
|
Kimimarokun Le Préféré de Johaaann
Nombre de messages : 37 Age : 32 Localisation : Web Date d'inscription : 20/03/2007
| Sujet: Re: Moteur HTTP Mer 21 Mar - 0:36 | |
| C'est beau quand c'est bien rédigé comme ça... | |
|
CedZbir
Nombre de messages : 9 Age : 39 Localisation : Derrière le maitre Date d'inscription : 20/03/2007
| Sujet: Re: Moteur HTTP Mer 21 Mar - 15:46 | |
| ça sert à envoyer pleins de bouzolettre pour spamer kapock | |
|
Kapock Sans Rang Spécial :D
Nombre de messages : 55 Age : 29 Localisation : Belgique Date d'inscription : 19/03/2007
| Sujet: Re: Moteur HTTP Mer 21 Mar - 17:08 | |
| | |
|