Option Strict On
Imports System.Runtime.InteropServices
'created by: loyalty
'Email: loyalty.exe@gmail.com
'Website: http://loyaltyHF.blogspot.com
Module Module1
'http://pinvoke.net/default.aspx/wininet.InternetOpen
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" ( _
ByVal sAgent As String, _
ByVal lAccessType As Int32, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal lFlags As Integer) As IntPtr
'http://pinvoke.net/default.aspx/wininet.InternetConnect
Private Declare Auto Function InternetConnect Lib "wininet.dll" ( _
ByVal hInternetSession As System.IntPtr, _
ByVal sServerName As String, _
ByVal nServerPort As Integer, _
ByVal sUsername As String, _
ByVal sPassword As String, _
ByVal lService As Int32, _
ByVal lFlags As Int32, _
ByVal lContext As System.IntPtr) As System.IntPtr
'http://pinvoke.net/default.aspx/wininet.InternetCloseHandle
Private Declare Function InternetCloseHandle Lib "wininet.dll" ( _
ByVal hInet As IntPtr) As Boolean
'http://www.pinvoke.net/default.aspx/wininet.InternetGetLastResponseInfo
Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" ( _
ByRef errorCode As Integer, _
ByVal buffer As String, _
ByRef bufferLength As Integer) As <MarshalAs(UnmanagedType.Bool)> Boolean
Private Declare Function HttpOpenRequest Lib "wininet.dll" Alias "HttpOpenRequestA" ( _
ByVal hHttpSession As IntPtr, _
ByVal lpszVerb As String, _
ByVal lpszObjectName As String, _
ByVal lpszVersion As String, _
ByVal lpszReferer As String, _
ByVal lpszAcceptTypes As String, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As IntPtr
Private Declare Function HttpSendRequest Lib "wininet.dll" Alias "HttpSendRequestA" ( _
ByVal hHttpRequest As IntPtr, _
ByVal lpszHeaders As String, _
ByVal dwHeadersLength As Integer, _
ByVal lpOptional As String, _
ByVal dwOptionalLength As Integer) As Boolean
Private Declare Function InternetReadFile Lib "wininet.dll" ( _
ByVal hFile As IntPtr, _
ByVal lpBuffer As String, _
ByVal dwNumberOfBytesToRead As Integer, _
ByRef lpNumberOfBytesRead As Integer) As Boolean
Private _connect As IntPtr
Private Property Connect() As IntPtr
Get
Return _connect
End Get
Set(ByVal value As IntPtr)
_connect = value
End Set
End Property
Private _hInet As IntPtr
Private Property hInet() As IntPtr
Get
Return _hInet
End Get
Set(ByVal value As IntPtr)
_hInet = value
End Set
End Property
Private _conneted As Boolean
Public Property Connected() As Boolean
Get
Return _conneted
End Get
Set(ByVal value As Boolean)
_conneted = value
End Set
End Property
Private Sub OpenConnection(ByVal address As String, ByVal user As String, ByVal pass As String)
hInet = InternetOpen("Internet Explorer", 1, vbNullString, vbNullString, 0)
If hInet = IntPtr.Zero Then
Connected = False
Else
Connect = InternetConnect(hInet, address, 80, user, pass, 3, 0, IntPtr.Zero)
If Connect = IntPtr.Zero Then
Connected = False
Else
Connected = True
End If
End If
End Sub
Sub Main()
Console.Title = "HTTP wininet test -loyalty"
Console.WriteLine("Url: http://pastebin.com/raw.php?i=di50yjGJ" & vbCrLf)
OpenConnection("pastebin.com", vbNullString, vbNullString)
If Connected Then
Dim req As IntPtr = HttpOpenRequest(Connect, "GET", "/raw.php?i=di50yjGJ", "HTTP/1.0", vbNullString, vbNullString, 524288, 0)
If Not req = IntPtr.Zero Then
If HttpSendRequest(req, vbNullString, 0, vbNullString, 0) Then
Dim s As String = Space(255)
Dim r As Integer
If InternetReadFile(req, s, Len(s), r) Then
Console.WriteLine("Page Content: " & s.TrimEnd)
Console.WriteLine("Content Length: " & r)
Else
Console.WriteLine("Error reading the file!")
End If
Else
Console.WriteLine("Error sending the request!")
End If
Else
Console.WriteLine("Error opening the request!")
End If
Else
Console.WriteLine("Unable to connect!")
End If
Console.ReadKey()
End Sub
End Module