Go Back   Gaming Gutter > Non-Gaming > Programming > Source Code


Source Code - Have a source code/project files you want to post? Do so here.

» Site Navigation
» Home
» FAQ
» Log in
User Name:

Password:

Not a member yet?
Register Now!
» Advertisement
» GG Stuff

Follow us on Twitter!

Get the GG toolbar today (for firefox only)
» Recent Threads
Go to first new post I Need a Favor!!! My...
Today 08:14 AM
by Charger
Last post by samstah
Today 10:19 AM
3 Replies, 30 Views
Go to first new post If you got a FFQ, what...
11-12-2009 12:22 AM
Last post by Collette
Today 10:08 AM
30 Replies, 371 Views
Go to first new post [[Gaming Gutter's...
11-16-2009 11:55 PM
Last post by Juanstin
Today 10:04 AM
3 Replies, 169 Views
Go to first new post Ruzzeh a.k.a kayla.......
Today 12:03 AM
Last post by tox tha fox
Today 10:03 AM
6 Replies, 46 Views
Go to first new post The Boring Poem.
11-17-2009 12:02 PM
Last post by thegreatme
Today 09:50 AM
3 Replies, 82 Views
Reply
 
LinkBack Thread Tools Display Modes

 [VB.NET] HTTPWrapper
Old 11-09-2008, 11:39 PM   #1 (permalink)
Banned

Male leptoon is offline
 
Join Date: Apr 2008
Posts: 178
GPoints: 693
iTrader: 12 / 100%
leptoon Is Recognizable
Rep Power: 0
[VB.NET] HTTPWrapper

Heres the wrapper used in the Omnipresent Autobuyer. Y'all might have some use for it...

Use:
Code:
Public vbWrapper(0) As Wrapper
Dim intWrapperID As Integer = lstAccounts.Items.Count
ReDim Preserve vbWrapper(intWrapperID)

Me.vbWrapper(intWrapperID) = New Wrapper()
Get:
Code:
strHTML = Me.vbWrapper(intWrapperID).Request("GET", "http://www.neopets.com/", "")
Post:
Code:
strHTML = Me.vbWrapper(intWrapperID).Request("POST", "http://www.neopets.com/hi.phtml?destination=%2Fpetcentral.phtml&username=" & strUsername, "http://www.neopets.com/loginpage.phtml")
Code:
'TcpClient Wrapper by Robawtic edited by leptoon
Imports System.Text.RegularExpressions
Imports System.Net
Imports System.IO
Imports System.Text
Imports System.IO.Compression
Imports System.Runtime.Serialization.Formatters.Binary
Public Class Wrapper
    Inherits System.Windows.Forms.UserControl
#Region " Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        'This call is required by the Windows Form Designer.
        InitializeComponent()
        'Add any initialization after the InitializeComponent() call
    End Sub
    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'Wrapper
        '
        Me.Name = "Wrapper"
        Me.ResumeLayout(False)

    End Sub
#End Region
    Private colCookies As New Collection
    Dim strCookies As String = Nothing
    Public LastPage As String
    Public ProxyHost As String
    Public ProxyPort As String
    Public strPost As String = Nothing
    Dim strHTML As String = Nothing
    Public Function Request(ByVal Method As String, ByVal URL As String, ByVal Referer As String) As String
        Dim Host As String = Nothing
        Dim strFile As String = Nothing
        Dim pos As Integer = 0
        If Referer Is Nothing Then
            Referer = LastPage
        End If
        If URL.Contains("http://") Then
            Host = URL.Substring(7)
        Else
            Host = URL
        End If
        If Host.Contains("/") Then
            pos = Host.IndexOf("/", 0)
            strFile = Host.Substring(pos)
            Host = Host.Substring(0, pos)
        Else
            strFile = "/"
        End If
        If Method = "POST" Then
            pos = strFile.IndexOf("?")
            If Not (pos = -1) Then
                strPost = strFile.Substring(pos + 1)
                strFile = strFile.Substring(0, pos)
            Else
                strPost = Nothing
            End If
        End If
        LastPage = URL
        Dim ReqHeaders As String
        If Method = "GET" OrElse Method = "PIC" Then
            ReqHeaders = "GET" + " " + strFile + " HTTP/1.1" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Host: " + Host + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Language: en-us,en;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Encoding: gzip, deflate" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Keep-Alive: 300" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: keep-alive" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Referer: " + Referer + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Cookie: " + strCookies + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & ""
        Else
            ReqHeaders = "POST" + " " + strFile + " HTTP/1.1" & Microsoft.VisualBasic.Chr(13) & Microsoft.VisualBasic.Chr(10) & "" + "Host: " + Host + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Language: en-us,en;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Encoding: gzip, deflate" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Keep-Alive: 300" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: keep-alive" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Referer: " + Referer + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Cookie: " + strCookies + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Content-Type: application/x-www-form-urlencoded" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Content-Length: 0" & Microsoft.VisualBasic.Chr(13) & Microsoft.VisualBasic.Chr(10) & "" + "Connection: close" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + strPost
        End If
        If Method = "PIC" Then
            ReqHeaders.Replace("Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", "Accept: image/png,*/*;q=0.5")
        End If

        Dim tcp As New System.Net.Sockets.TcpClient
        Dim netstream As System.Net.Sockets.NetworkStream
        Dim TN(1) As Long
        If Referer = "" Then Referer = LastPage
        If InStr(1, URL, "http://") <> 0 Then Host = Mid$(URL, 8)
        If InStr(1, Host, "/") <> 0 Then Host = Mid$(Host, 1, InStr(1, Host, "/") - 1)
        If InStr(1, Host, "?") <> 0 Then Host = Mid$(Host, 1, InStr(1, Host, "?") - 1)
        'If Mid$(Host, 1, 4) = "www." Then Host = Mid$(Host, 5)
        LastPage = URL

        Try
            If ProxyPort = "" And ProxyHost = "" Then
                tcp.Connect(Host, 80) 'edited for proxy support
            Else
                tcp.Connect(ProxyHost, ProxyPort)
            End If
        Catch ex As Exception
            Return ex.Message
        End Try

        Dim sendbytes As Byte()
        sendbytes = System.Text.Encoding.ASCII.GetBytes(ReqHeaders)
        netstream = tcp.GetStream()
        netstream.Write(sendbytes, 0, sendbytes.Length)
        Dim sr As StreamReader = New StreamReader(netstream, Encoding.Default)
        Dim strHTML As String = sr.ReadToEnd
        Dim strParts As String() = Regex.Split(strHTML, Environment.NewLine + Environment.NewLine)
        strCookies = ParseCookies(strParts(0))
        If strParts(0).Contains("Content-Encoding") Then
            strParts(1) = DecompressGzip(strParts(1))
        End If

        Return strParts(0) + Environment.NewLine + Environment.NewLine + strParts(1)
    End Function
    Public Function DecompressGzip(ByVal compressed As String) As String
        Dim memStream As MemoryStream = New MemoryStream(System.Text.Encoding.Default.GetBytes(compressed))
        Dim decompressStream As GZipStream = New GZipStream(memStream, CompressionMode.Decompress)
        Dim endBytes(4) As Byte
        Dim position As Integer = CType(memStream.Length, Integer) - 4
        memStream.Position = position
        memStream.Read(endBytes, 0, 4)
        memStream.Position = 0
        Dim buffer(BitConverter.ToInt32(endBytes, 0) + 100) As Byte
        Dim offset As Integer = 0
        Dim total As Integer = 0
        While True
            Dim bytesRead As Integer = decompressStream.Read(buffer, offset, 100)
            If bytesRead = 0 Then
                Exit While
            End If
            offset += bytesRead
            total += bytesRead
        End While
        Return Encoding.ASCII.GetString(buffer)
    End Function
    Public Function ParseCookies(ByVal Headers As String) As String
        ParseCookies = ""
        Dim reg As Regex
        Dim matches As MatchCollection
        Dim match As Match
        reg = New Regex("set-cookie:\s*([^=]+)=([^;]+);", RegexOptions.IgnoreCase)
        If reg.IsMatch(Headers) Then
            matches = reg.Matches(Headers)
            For Each match In matches
                Try
                    colCookies.Add(match.Groups(1).ToString & "=" & match.Groups(2).ToString, match.Groups(1).ToString)
                Catch ex As Exception
                    colCookies.Remove(match.Groups(1).ToString)
                    colCookies.Add(match.Groups(1).ToString & "=" & match.Groups(2).ToString, match.Groups(1).ToString)
                End Try
            Next
        End If
        Dim i As Long
        For i = 1 To colCookies.Count Step 1
            ParseCookies = ParseCookies & colCookies.Item(i).ToString & ";"
        Next
    End Function
    Public Function StripHeaders(ByVal strSource As String) As String
        Dim strParts() As String = Regex.Split(strSource, Environment.NewLine + Environment.NewLine + "([a-zA-Z0-9]*)" + Environment.NewLine)
        Return strParts(2)
    End Function
    Private Shared Sub Pause(ByVal seconds As Double)
        Dim num As Double = seconds * 1000
        Dim t1 As DateTime = DateTime.Now
        Dim t2 As DateTime = DateTime.Now
        Dim tmDiff As TimeSpan = t2 - t1
        While Convert.ToDouble(tmDiff.TotalMilliseconds.ToString) < num
            t2 = DateTime.Now
            tmDiff = t2 - t1
            Application.DoEvents()
        End While
    End Sub
    Public Function GrabPic(ByVal strURL As String) As System.Drawing.Image
        Dim memStream As New MemoryStream(System.Text.Encoding.Default.GetBytes(StripHeaders(Request("GET", strURL, LastPage))))
        GrabPic = Image.FromStream(memStream)
        Return GrabPic
    End Function
    Public Sub ClearCookies()
        colCookies.Clear()
        strCookies = Nothing
    End Sub
End Class
+Rep if it helped, please.

Last edited by leptoon; 11-09-2008 at 11:56 PM..
  Reply With Quote
The Following 3 Users Say Thank You to leptoon For This Useful Post:
andrew. (08-17-2009), Kayolix. (03-24-2009), mehike (09-25-2009)

 
Old 09-23-2009, 10:05 AM   #2 (permalink)
Full Member

Male Ozzy123 is offline
 
Ozzy123's Avatar
 
Join Date: Apr 2009
Location: Costa Rica
Posts: 144
GPoints: 2,005
iTrader: 0 / 0%
Ozzy123 Is Recognizable
Rep Power: 2
can you send me this but for gaiaonline in a pm please thanks
__________________
HTML Code:
http://ozzy12323.elbruto.es/
  Reply With Quote
Reply

Bookmarks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Powered by vBadvanced CMPS v3.1.0

All times are GMT -7. The time now is 12:07 PM.


vBulletin skin developed by: eXtremepixels
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The contents of this webpage are copyright © 2006-2008 GamingGutter.com. All Rights Reserved.

Page generated in 0.12482691 seconds (100.00% PHP - 0% MySQL) with 21 queries