1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[VB.NET] Neopets Programming Tutorial

Discussion in 'Code Snippets and Tutorials' started by tharoux, May 28, 2009.

  1. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    Version: 1.0
    Made By: Tharoux
    Date: May 27th, 2009
    Revision: May 27th, 2009
    Goal: Creating a simple application that will log in Neopets and search for an item from the SW

    Since alot of peoples want to start programming for this forum and need help, I'll show you the basis and what you need to successfully create an application using VB.NET. I'm by no mean a professional programmer (Well, I am doing this for a living but not in VB.NET) so the code can probably be improve. Anyway, enough talking, let's get down to business.

    Disclaimer: I apologize for any typo, weird words, unreadable sentences: english is not my main language and I'm not perfect so if you see any problem with this tutorial, let me know so I can fix it.

    • ->Chapter One: Requirement
      ->Chapter Two: HTTPWrapper
      ->Chapter Three: Creation Of The Form
      ->Chapter Four: The Coding
      ->Chapter Five: Using Etherdetect
      ->Chapter Six: Using the HTTPWrapper Request
      ->The End


    Chapter One: Requirement

    The first thing we need to do is get the right tool. What I'm using can be replace and if you're more familiar with other programs/code, feel free to use what you're used to.

    You can use any VB.NET version and it will work but this one is free for 30 days. As for Etherdetect, you can easily find a serial on the web but you can still use the program without one.



    Chapter Two: HTTPWrapper

    There's some function in VB.NET that are readily available that will do part of the job regarding http request. But since we need a complete solution handling POST/GET request, cookies and image grabbing, someone managed to create a Class that can be used with VB.NET to handle all this for us. If I remember correctly, the one provided below was posted by Mystical (not a member of here anymore). I can't remember if I made some modifications to it but I do remember that I had to fiddle with the code a bit to make it work.

    Code (Text):
    1. Public Class TCPWrapper
    2.     Inherits System.Windows.Forms.UserControl
    3. #Region " Windows Form Designer generated code "
    4.     Public Sub New()
    5.         MyBase.New()
    6.         'This call is required by the Windows Form Designer.
    7.         InitializeComponent()
    8.         'Add any initialization after the InitializeComponent() call
    9.     End Sub
    10.     'UserControl overrides dispose to clean up the component list.
    11.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    12.         If disposing Then
    13.             If Not (components Is Nothing) Then
    14.                 components.Dispose()
    15.             End If
    16.         End If
    17.         MyBase.Dispose(disposing)
    18.     End Sub
    19.     'Required by the Windows Form Designer
    20.     Private components As System.ComponentModel.IContainer
    21.     'NOTE: The following procedure is required by the Windows Form Designer
    22.     'It can be modified using the Windows Form Designer.
    23.     'Do not modify it using the code editor.
    24.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    25.         components = New System.ComponentModel.Container
    26.     End Sub
    27. #End Region
    28.     Private colCookies As New Collection
    29.     Dim strCookies As String
    30.     Public LastPage As String
    31.     Public Function Request(ByVal Method As String, ByVal URL As String, ByVal Referer As String) As String
    32.         Dim Host As String = Nothing
    33.         Dim strFile As String = Nothing
    34.         Dim strPost As String = Nothing
    35.         Dim pos As Integer = 0
    36.         If Referer Is Nothing Then
    37.             Referer = LastPage
    38.         End If
    39.         If URL.Contains("http://") Then
    40.             Host = URL.Substring(7)
    41.         Else
    42.             Host = URL
    43.         End If
    44.         If Host.Contains("/") Then
    45.             pos = Host.IndexOf("/", 0)
    46.             strFile = Host.Substring(pos)
    47.             Host = Host.Substring(0, pos)
    48.         Else
    49.             strFile = "/"
    50.         End If
    51.         If Method = "POST" Then
    52.             pos = strFile.IndexOf("?")
    53.             If Not (pos = -1) Then
    54.                 strPost = strFile.Substring(pos + 1)
    55.                 strFile = strFile.Substring(0, pos)
    56.             Else
    57.                 strPost = Nothing
    58.             End If
    59.         End If
    60.         If Method = "POST2" Then
    61.             pos = strFile.IndexOf("?")
    62.             If Not (pos = -1) Then
    63.                 strPost = strFile.Substring(pos + 1)
    64.                 strFile = strFile.Substring(0, pos)
    65.             Else
    66.                 strPost = ""
    67.             End If
    68.         End If
    69.         LastPage = URL
    70.         Dim ReqHeaders As String = Nothing
    71.         If Method = "GET" OrElse Method = "PIC" Then
    72.             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 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & 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) & ""
    73.         Else
    74.             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 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & 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: " + strPost.Length.ToString + "" & 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
    75.         End If
    76.         If Method = "PIC" Then
    77.             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")
    78.         End If
    79.  
    80.         Dim tcp As New System.Net.Sockets.TcpClient
    81.         Dim netstream As System.Net.Sockets.NetworkStream
    82.         Dim TN(1) As Long
    83.         If Referer = "" Then Referer = LastPage
    84.         If InStr(1, URL, "http://") <> 0 Then Host = Mid$(URL, 8)
    85.         If InStr(1, Host, "/") <> 0 Then Host = Mid$(Host, 1, InStr(1, Host, "/") - 1)
    86.         If InStr(1, Host, "?") <> 0 Then Host = Mid$(Host, 1, InStr(1, Host, "?") - 1)
    87.         LastPage = URL
    88.         Try
    89.             tcp.Connect(Host, 80)
    90.         Catch ex As Exception
    91.             Return ex.Message
    92.         End Try
    93.  
    94.         Dim sendbytes As Byte()
    95.         sendbytes = System.Text.Encoding.ASCII.GetBytes(ReqHeaders)
    96.         netstream = tcp.GetStream()
    97.         netstream.Write(sendbytes, 0, sendbytes.Length)
    98.         Dim sr As StreamReader = New StreamReader(netstream, Encoding.Default)
    99.         Dim strHTML As String = sr.ReadToEnd
    100.         Dim strParts As String() = Regex.Split(strHTML, Environment.NewLine + Environment.NewLine)
    101.         strCookies = ParseCookies(strParts(0))
    102.         If strParts(0).Contains("Content-Encoding") Then
    103.             strParts(1) = DecompressGzip(strParts(1))
    104.         End If
    105.  
    106.         Return strParts(0) + Environment.NewLine + Environment.NewLine + strParts(1)
    107.     End Function
    108.     Public Function DecompressGzip(ByVal compressed As String) As String
    109.         Dim memStream As MemoryStream = New MemoryStream(System.Text.Encoding.Default.GetBytes(compressed))
    110.         Dim decompressStream As GZipStream = New GZipStream(memStream, CompressionMode.Decompress)
    111.         Dim endBytes(4) As Byte
    112.         Dim position As Integer = CType(memStream.Length, Integer) - 4
    113.         memStream.Position = position
    114.         memStream.Read(endBytes, 0, 4)
    115.         memStream.Position = 0
    116.         Dim buffer(BitConverter.ToInt32(endBytes, 0) + 100) As Byte
    117.         Dim offset As Integer = 0
    118.         Dim total As Integer = 0
    119.         While True
    120.             Dim bytesRead As Integer = decompressStream.Read(buffer, offset, 100)
    121.             If bytesRead = 0 Then
    122.                 Exit While
    123.             End If
    124.             offset += bytesRead
    125.             total += bytesRead
    126.         End While
    127.         Return Encoding.ASCII.GetString(buffer)
    128.     End Function
    129.     Public Function ParseCookies(ByVal Headers As String) As String
    130.         ParseCookies = ""
    131.         Dim reg As Regex
    132.         Dim matches As MatchCollection
    133.         Dim match As Match
    134.         reg = New Regex("set-cookie:\s*([^=]+)=([^;]+);", RegexOptions.IgnoreCase)
    135.         If reg.IsMatch(Headers) Then
    136.             matches = reg.Matches(Headers)
    137.             For Each match In matches
    138.                 Try
    139.                     colCookies.Add(match.Groups(1).ToString & "=" & match.Groups(2).ToString, match.Groups(1).ToString)
    140.                 Catch ex As Exception
    141.                     colCookies.Remove(match.Groups(1).ToString)
    142.                     colCookies.Add(match.Groups(1).ToString & "=" & match.Groups(2).ToString, match.Groups(1).ToString)
    143.                 End Try
    144.             Next
    145.         End If
    146.         Dim i As Long
    147.         For i = 1 To colCookies.Count Step 1
    148.             ParseCookies = ParseCookies & colCookies.Item(i).ToString & ";"
    149.         Next
    150.     End Function
    151.     Public Function StripHeaders(ByVal strSource As String) As String
    152.         Dim strParts() As String = Regex.Split(strSource, Environment.NewLine + Environment.NewLine)
    153.         Return strParts(1)
    154.     End Function
    155.     Public Function NeoLogin(ByVal user As String, ByVal pass As String, ByRef loggedIn As Boolean) As String
    156.         Dim strHTML As String = Nothing
    157.         Request("GET", "http://www.neopets.com/loginpage.phtml", "http://www.google.com")
    158.         Pause(1)
    159.         Request("POST", "http://www.neopets.com/hi.phtml?destination=%2Findex.phtml&username=" + user, "http://www.neopets.com/loginpage.phtml")
    160.         Pause(1)
    161.         strHTML = Request("POST", "http://www.neopets.com/login.phtml?username=" + user + "&password=" + pass + "&destination=%2Findex.phtml", "http://www.neopets.com/hi.phtml")
    162.         If strHTML.Contains("Set-Cookie: neologin=") Then
    163.             loggedIn = True
    164.             Return "Logged In"
    165.         Else
    166.             If strHTML.Contains("too many times") Then
    167.                 loggedIn = False
    168.                 Return "To Many Login Attempts"
    169.             Else
    170.                 If strHTML.Contains("badpassword") Then
    171.                     loggedIn = False
    172.                     Return "Wrong Username/Password"
    173.                 Else
    174.                     If strHTML.Contains("frozen") Then
    175.                         loggedIn = False
    176.                         Return "Account Frozen"
    177.                     Else
    178.                         If strHTML.Contains("just a technical problem") Then
    179.                             loggedIn = False
    180.                             Return "Neopets is down for maintenance"
    181.                         Else
    182.                             loggedIn = False
    183.                             Return "Unknow Error"
    184.                         End If
    185.                     End If
    186.                 End If
    187.             End If
    188.         End If
    189.     End Function
    190.     Private Shared Sub Pause(ByVal seconds As Double)
    191.         Dim num As Double = seconds * 1000
    192.         Dim t1 As DateTime = DateTime.Now
    193.         Dim t2 As DateTime = DateTime.Now
    194.         Dim tmDiff As TimeSpan = t2 - t1
    195.         While Convert.ToDouble(tmDiff.TotalMilliseconds.ToString) < num
    196.             t2 = DateTime.Now
    197.             tmDiff = t2 - t1
    198.             Application.DoEvents()
    199.         End While
    200.     End Sub
    201.     Public Function GrabPic(ByVal strURL As String) As System.Drawing.Image
    202.         Dim memStream As New MemoryStream(System.Text.Encoding.Default.GetBytes(StripHeaders(Request("GET", strURL, LastPage))))
    203.         GrabPic = Image.FromStream(memStream)
    204.         Return GrabPic
    205.     End Function
    206.     Public Sub ClearCookies()
    207.         colCookies.Clear()
    208.         strCookies = Nothing
    209.     End Sub
    210.     Public Function GetBetween(ByVal Source As String, ByVal Start As String, ByVal Finish As String) As String
    211.         Dim Result = ""
    212.         Dim A = InStr(1, Source, Start) + Len(Start)
    213.         If A = 0 Then
    214.             Result = ""
    215.             Return Result
    216.         Else
    217.             Dim B = InStr(A, Source, Finish)
    218.             If B = 0 Then
    219.                 Result = ""
    220.                 Return Result
    221.             Else
    222.                 Result = Mid(Source, A, B - A)
    223.                 Return Result
    224.             End If
    225.         End If
    226.     End Function
    227. End Class
    Now, let's see what function we have in there and what you can do with them. Note that some functions are called within the class so you're never going to call them yourself. We'll see later with examples how to use them.

    -Function Request(): This one is used to send a command to the server. You can either use "GET". "POST" or "PIC" depending on what you need to do.
    -Function NeoLogin(): This function can be done manually but since it's so common, they create a function out of it to make the thing easier.
    -Function Pause(): Will pause for xx seconds.
    -Function GrabPic(): If you want to retrieve a pic from the source code, you'll use function.
    -Function ClearCookie(): Delete all the cookie strings kept after using the neologin function.
    -Function GetBetween(): Added by me. This will return a string contained between 2 others.



    Chapter Three: Creation Of The Form

    Now that we have everything we need, let's start coding. First, we need to create a new project.

    So in VB.NET:
    File --> New Project --> Select "Windows Form Application"

    Give it the name you want, it doesn't matter. You'll need to put 2 "textbox", a "label" and 2 "command button".
    We'll use the first box for the neopets username and the second one for the password.

    [​IMG]



    Chapter Four: The Coding

    We need to put some code in there to make everything work. First, double-click on the "Login" button.
    That will bring the code window. It's now the time to put the HTTPWrapper from the chapter 2 in our project. Copy/paste it but make sure you do it after the "End Class" already in there. Right ahead, you'll notice some errors in the "Error window" at the bottom. That's normal. VB.Net does handle all this code but not right out off the box. That's where "Imports" come into play. Basicaly, you'll tell VB.Net where to find the extra function used in the HTTPWrapper.

    Here's all the "Imports" you need. Imports MUST be before ALL the code in you code window.

    Code (Text):
    1. Imports System.Net
    2. Imports System.Text.RegularExpressions
    3. Imports System.IO
    4. Imports System.Text
    5. Imports System.IO.Compression
    Now, let's get back to our main form (still in the code window). You can easily find it because the class will have the name of your project you defined in chapter 3. You must understand that even if the HTTPWrapper is in the same code window, this class is not interacting with your main class. You have to create a relation between them for your main class to be able to use it.

    This is done using the code below. This section of code must be in your main class at the very beginning. Each time we'll have to use the HTTPWrapper, we will use this link to communicate with it.
    Code (Text):
    1. Private Wrapper As New TCPWrapper
    It's now time to do our first interaction with http://www.neopets.com. To be able to do anything, we first need to be logged in. So we'll move to the "Private Sub Button1_Click" part within our main class. The code we put there will be executed upon the successfull click of the "Login" button on our form. I will not put any confirmation of the information entered into the textbox to facilitate the reading of the code. This won't impact the process at all, it's just a safety. If you want a complete login function, you can follow THIS link containing a complete solution made by me containing all the standard validation for the login button (Field not empty, disabling of the field to prevent editing after logging in).

    Using the Neologin() function already coded in the HTTPWrapper is easy. This function navigate throught all the normal pages if you were trying to do it manually with your browser (loginpage.phtml --> hi.phtml --> login.phtml). The only reason they did a function is to prevent you from doing a 100 lines of codes each time. Instead, all we need is a single (!) line. Another nice thing about the HTTPWrapper is that it always return a string with the result of the operation you just ask. It's up to you to store this information in a string variable or not depending on what you want to do with the result.

    Code (Text):
    1. Dim Response = Wrapper.NeoLogin(TextBox1.Text, TextBox2.Text, False)
    In the example above, we can see that we're using the "Wrapper" keyword. Remember, this is our link between the main class and the HTTPWrapper class.
    We than ask the link to execute the function Neologin. What we put in parenthesis is parameters given to the HTTPWrapper to complete the operation (textbox1.text = username we input on the form, textbox2.text = password) so it can perform the login. The result will be put in the variable "Response" for further analysis.

    If you take a close look into the Neologin() function in the HTTPWrapper, you'll notice that all the possible answers from TnT are already coded to simplify the task. Here's what the Wrapper can return as a result of the login process:
    • -"Logged In"
      -"To Many Login Attempts"
      -"Wrong Username/Password"
      -"Account Frozen"
      -"Neopets is down for maintenance"
      -"Unknow Error"

    Right now, the result is not displayed anywhere. We'll use the label made earlier to show the result of the operation and if everything was done perfectly, including the user/password, we should see "Logged In" in the label below the 2 textbox.
    Code (Text):
    1. Label1.Text = Response
    It's time to complete the "Logout" button. This one is easy because it's only 1 line of code to remove all the cookies. Clearing the cookie will log you out of http://www.neopets.com. To do so, return to your form (the GUI) and double-click on the "Logout" button. You'll automaticaly be redirect to the right place and all you need to put there is this.
    Code (Text):
    1. Wrapper.ClearCookies()
    Here's what your code should look like after this chapter:

    Code (Text):
    1. Imports System.Net
    2. Imports System.Text.RegularExpressions
    3. Imports System.IO
    4. Imports System.Text
    5. Imports System.IO.Compression
    6.  
    7. Public Class Form1
    8.     Private Wrapper As New TCPWrapper
    9.  
    10.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    11.         Dim Response = Wrapper.NeoLogin(TextBox1.Text, TextBox2.Text, False)
    12.         Label1.Text = Response
    13.     End Sub
    14.  
    15.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    16.         Wrapper.ClearCookies()
    17.     End Sub
    18. End Class
    19.  
    20. Public Class TCPWrapper
    21.     Inherits System.Windows.Forms.UserControl
    22. #Region " Windows Form Designer generated code "
    23.     Public Sub New()
    24.         MyBase.New()
    25.         'This call is required by the Windows Form Designer.
    26.         InitializeComponent()
    27.         'Add any initialization after the InitializeComponent() call
    28.     End Sub
    29.     'UserControl overrides dispose to clean up the component list.
    30.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    31.         If disposing Then
    32.             If Not (components Is Nothing) Then
    33.                 components.Dispose()
    34.             End If
    35.         End If
    36.         MyBase.Dispose(disposing)
    37.     End Sub
    38.     'Required by the Windows Form Designer
    39.     Private components As System.ComponentModel.IContainer
    40.     'NOTE: The following procedure is required by the Windows Form Designer
    41.     'It can be modified using the Windows Form Designer.
    42.     'Do not modify it using the code editor.
    43.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    44.         components = New System.ComponentModel.Container
    45.     End Sub
    46. #End Region
    47.     Private colCookies As New Collection
    48.     Dim strCookies As String
    49.     Public LastPage As String
    50.     Public Function Request(ByVal Method As String, ByVal URL As String, ByVal Referer As String) As String
    51.         Dim Host As String = Nothing
    52.         Dim strFile As String = Nothing
    53.         Dim strPost As String = Nothing
    54.         Dim pos As Integer = 0
    55.         If Referer Is Nothing Then
    56.             Referer = LastPage
    57.         End If
    58.         If URL.Contains("http://") Then
    59.             Host = URL.Substring(7)
    60.         Else
    61.             Host = URL
    62.         End If
    63.         If Host.Contains("/") Then
    64.             pos = Host.IndexOf("/", 0)
    65.             strFile = Host.Substring(pos)
    66.             Host = Host.Substring(0, pos)
    67.         Else
    68.             strFile = "/"
    69.         End If
    70.         If Method = "POST" Then
    71.             pos = strFile.IndexOf("?")
    72.             If Not (pos = -1) Then
    73.                 strPost = strFile.Substring(pos + 1)
    74.                 strFile = strFile.Substring(0, pos)
    75.             Else
    76.                 strPost = Nothing
    77.             End If
    78.         End If
    79.         If Method = "POST2" Then
    80.             pos = strFile.IndexOf("?")
    81.             If Not (pos = -1) Then
    82.                 strPost = strFile.Substring(pos + 1)
    83.                 strFile = strFile.Substring(0, pos)
    84.             Else
    85.                 strPost = ""
    86.             End If
    87.         End If
    88.         LastPage = URL
    89.         Dim ReqHeaders As String = Nothing
    90.         If Method = "GET" OrElse Method = "PIC" Then
    91.             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 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & 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) & ""
    92.         Else
    93.             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 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & 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: " + strPost.Length.ToString + "" & 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
    94.         End If
    95.         If Method = "PIC" Then
    96.             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")
    97.         End If
    98.  
    99.         Dim tcp As New System.Net.Sockets.TcpClient
    100.         Dim netstream As System.Net.Sockets.NetworkStream
    101.         Dim TN(1) As Long
    102.         If Referer = "" Then Referer = LastPage
    103.         If InStr(1, URL, "http://") <> 0 Then Host = Mid$(URL, 8)
    104.         If InStr(1, Host, "/") <> 0 Then Host = Mid$(Host, 1, InStr(1, Host, "/") - 1)
    105.         If InStr(1, Host, "?") <> 0 Then Host = Mid$(Host, 1, InStr(1, Host, "?") - 1)
    106.         LastPage = URL
    107.         Try
    108.             tcp.Connect(Host, 80)
    109.         Catch ex As Exception
    110.             Return ex.Message
    111.         End Try
    112.  
    113.         Dim sendbytes As Byte()
    114.         sendbytes = System.Text.Encoding.ASCII.GetBytes(ReqHeaders)
    115.         netstream = tcp.GetStream()
    116.         netstream.Write(sendbytes, 0, sendbytes.Length)
    117.         Dim sr As StreamReader = New StreamReader(netstream, Encoding.Default)
    118.         Dim strHTML As String = sr.ReadToEnd
    119.         Dim strParts As String() = Regex.Split(strHTML, Environment.NewLine + Environment.NewLine)
    120.         strCookies = ParseCookies(strParts(0))
    121.         If strParts(0).Contains("Content-Encoding") Then
    122.             strParts(1) = DecompressGzip(strParts(1))
    123.         End If
    124.  
    125.         Return strParts(0) + Environment.NewLine + Environment.NewLine + strParts(1)
    126.     End Function
    127.     Public Function DecompressGzip(ByVal compressed As String) As String
    128.         Dim memStream As MemoryStream = New MemoryStream(System.Text.Encoding.Default.GetBytes(compressed))
    129.         Dim decompressStream As GZipStream = New GZipStream(memStream, CompressionMode.Decompress)
    130.         Dim endBytes(4) As Byte
    131.         Dim position As Integer = CType(memStream.Length, Integer) - 4
    132.         memStream.Position = position
    133.         memStream.Read(endBytes, 0, 4)
    134.         memStream.Position = 0
    135.         Dim buffer(BitConverter.ToInt32(endBytes, 0) + 100) As Byte
    136.         Dim offset As Integer = 0
    137.         Dim total As Integer = 0
    138.         While True
    139.             Dim bytesRead As Integer = decompressStream.Read(buffer, offset, 100)
    140.             If bytesRead = 0 Then
    141.                 Exit While
    142.             End If
    143.             offset += bytesRead
    144.             total += bytesRead
    145.         End While
    146.         Return Encoding.ASCII.GetString(buffer)
    147.     End Function
    148.     Public Function ParseCookies(ByVal Headers As String) As String
    149.         ParseCookies = ""
    150.         Dim reg As Regex
    151.         Dim matches As MatchCollection
    152.         Dim match As Match
    153.         reg = New Regex("set-cookie:\s*([^=]+)=([^;]+);", RegexOptions.IgnoreCase)
    154.         If reg.IsMatch(Headers) Then
    155.             matches = reg.Matches(Headers)
    156.             For Each match In matches
    157.                 Try
    158.                     colCookies.Add(match.Groups(1).ToString & "=" & match.Groups(2).ToString, match.Groups(1).ToString)
    159.                 Catch ex As Exception
    160.                     colCookies.Remove(match.Groups(1).ToString)
    161.                     colCookies.Add(match.Groups(1).ToString & "=" & match.Groups(2).ToString, match.Groups(1).ToString)
    162.                 End Try
    163.             Next
    164.         End If
    165.         Dim i As Long
    166.         For i = 1 To colCookies.Count Step 1
    167.             ParseCookies = ParseCookies & colCookies.Item(i).ToString & ";"
    168.         Next
    169.     End Function
    170.     Public Function StripHeaders(ByVal strSource As String) As String
    171.         Dim strParts() As String = Regex.Split(strSource, Environment.NewLine + Environment.NewLine)
    172.         Return strParts(1)
    173.     End Function
    174.     Public Function NeoLogin(ByVal user As String, ByVal pass As String, ByRef loggedIn As Boolean) As String
    175.         Dim strHTML As String = Nothing
    176.         Request("GET", "http://www.neopets.com/loginpage.phtml", "http://www.google.com")
    177.         Pause(1)
    178.         Request("POST", "http://www.neopets.com/hi.phtml?destination=%2Findex.phtml&username=" + user, "http://www.neopets.com/loginpage.phtml")
    179.         Pause(1)
    180.         strHTML = Request("POST", "http://www.neopets.com/login.phtml?username=" + user + "&password=" + pass + "&destination=%2Findex.phtml", "http://www.neopets.com/hi.phtml")
    181.         If strHTML.Contains("Set-Cookie: neologin=") Then
    182.             loggedIn = True
    183.             Return "Logged In"
    184.         Else
    185.             If strHTML.Contains("too many times") Then
    186.                 loggedIn = False
    187.                 Return "To Many Login Attempts"
    188.             Else
    189.                 If strHTML.Contains("badpassword") Then
    190.                     loggedIn = False
    191.                     Return "Wrong Username/Password"
    192.                 Else
    193.                     If strHTML.Contains("frozen") Then
    194.                         loggedIn = False
    195.                         Return "Account Frozen"
    196.                     Else
    197.                         If strHTML.Contains("just a technical problem") Then
    198.                             loggedIn = False
    199.                             Return "Neopets is down for maintenance"
    200.                         Else
    201.                             loggedIn = False
    202.                             Return "Unknow Error"
    203.                         End If
    204.                     End If
    205.                 End If
    206.             End If
    207.         End If
    208.     End Function
    209.     Private Shared Sub Pause(ByVal seconds As Double)
    210.         Dim num As Double = seconds * 1000
    211.         Dim t1 As DateTime = DateTime.Now
    212.         Dim t2 As DateTime = DateTime.Now
    213.         Dim tmDiff As TimeSpan = t2 - t1
    214.         While Convert.ToDouble(tmDiff.TotalMilliseconds.ToString) < num
    215.             t2 = DateTime.Now
    216.             tmDiff = t2 - t1
    217.             Application.DoEvents()
    218.         End While
    219.     End Sub
    220.     Public Function GrabPic(ByVal strURL As String) As System.Drawing.Image
    221.         Dim memStream As New MemoryStream(System.Text.Encoding.Default.GetBytes(StripHeaders(Request("GET", strURL, LastPage))))
    222.         GrabPic = Image.FromStream(memStream)
    223.         Return GrabPic
    224.     End Function
    225.     Public Sub ClearCookies()
    226.         colCookies.Clear()
    227.         strCookies = Nothing
    228.     End Sub
    229.     Public Function GetBetween(ByVal Source As String, ByVal Start As String, ByVal Finish As String) As String
    230.         Dim Result = ""
    231.         Dim A = InStr(1, Source, Start) + Len(Start)
    232.         If A = 0 Then
    233.             Result = ""
    234.             Return Result
    235.         Else
    236.             Dim B = InStr(A, Source, Finish)
    237.             If B = 0 Then
    238.                 Result = ""
    239.                 Return Result
    240.             Else
    241.                 Result = Mid(Source, A, B - A)
    242.                 Return Result
    243.             End If
    244.         End If
    245.     End Function
    246. End Class


    Chapter Five: Using Etherdetect

    This program might be hard to understand at first but once you get the twist, it's quite easy.
    To use this program, you need to be logged in normally using your browser. To do the sniffing, you will need to perform the action yourself and than analyze the result in etherdetect to find what the browser is really doing behind the GUI.

    To do so, click the play button in etherdect. This will start the sniffing process.
    [​IMG]

    Than do what you have to do on http://www.neopets.com. In this example, I'll be searching the SW for a "bri codestone", using the "indentical to my phrase" option.
    When this is done, click the stop button in etherdetect.
    [​IMG]

    The key here is to find where's the information we want. Browse throught all entry until you see something with "GET" in it. Over time, you'll realize that TnT's ip adress is 206.220.42.181 so this narrow where you have to search to find the information you're looking for. Click on the picture below for a better view.
    [​IMG]

    Ok, so we've found what you're looking for, now it's time to gather data. When using the HTTPWrapper, we need 3 things:
    -Is it a "GET" or "POST" command
    -the complete URL of the page
    -the referer

    The referer is VERY important. TnT use this as a security to be sure you're not trying to cheat, and if you don't have it, the action you're trying to do will not work.

    In the example below, I selected the line where was the "GET" command(STEP 1). Next, you have to press the data tab at the bottom for a better view of the information(Step 2). Now, we can see that we are doing a "GET", that the url is "www.neopets.com/market.phtml?type=wizard" and that the referer (where we are coming from) is "http://www.neopets.com/index.phtml". Basicaly, this is the link to the SW main page. Click on the picture below for a better view.
    [​IMG]

    Here's an example with the "POST" command. It work exactly like the "GET" command. There's just 1 extra line we need to see there (all the parameters that will be sent with the "POST"). On the third line, we see all the informations that need to be sent. Here, we are doing a "POST", the url is "www.neopets.com/market.phtml?type=process_wizard&feedset=0&shopwizard=bri+codestone&table=shop&criteria=exact&min_price=0&max_price=99999"
    and the referer is "http://www.neopets.com/market.phtml?type=wizard". Here we can see the item we searched for (Bri codestone) and the "Identical to my phrase" option (criteria=exact).Click on the picture below for a better view.
    [​IMG]

    It's the same process everytime. It may get more complex depending on what you're trying to code but the step remains the same.



    Chapter Six: Using the HTTPWrapper Request

    Here's where the real interaction between your program and http://www.neopets.com will take place. In this chapter, we'll add a nice SW function to our project. We already found all the informations we need to make this happen in the last chapter so now it's only a matter of coding it.

    In the last chapter, I wrote about the referer playing an important part in our coding. I'll explain why and how I code my programs accordingly. I'm doing this mainly because everytime I (or any programmer) do a program, we must think about what can be done to prevent TnT from catching us. Nobody want a program with a freeze rate of 95%. And this start with how you navigate throught the URL in your programs. I always imagine myself browsing neopets in a single window: No tab, no shortcut. For every action, I think about where I'm going and how to get there. In the last chapter, we can see this. I was searching for an item from the SW but instead of just doing the search using the "POST" command with the right URL, I first navigated my way to the SW using the "GET" command with the right URL. And that's where the referer become important. When moving from page to page, you must be sure that the referer you coded is the right one, making the process as human as possible.

    Maybe doing all this is a waste of time, but IMO, the more human your program act, the less chance you have of getting caught. Anyway, enough talking, let's get down to business.

    We'll now add a textbox and a command button to our form. We'll use the textbox to ouput the result of the SW search.

    [​IMG]

    Now, double-click on the "Search" button to open the code window. Like I said earlier, we won't directly do the search: we'll start by navigating our way to the SW first. In the last chapter, we found that we were doing a "GET", that the url was "www.neopets.com/market.phtml?type=wizard" and that the referer was "http://www.neopets.com/index.phtml".

    Code (Text):
    1. Wrapper.Request("GET", "www.neopets.com/market.phtml?type=wizard", "http://www.neopets.com/index.phtml")
    No need to store the result in a variable since this will only display the SW main page. Since there's no important information there, we'll discard it.

    Now we need to do the actual search. Again refering to the last chapter, we can complete the code. This time, we will store the result in the variable "Response" because you may want to process this information after (I.E. get the price of this item).

    Code (Text):
    1. Dim Response = Wrapper.Request("POST", "http://www.neopets.com/market.phtml?type=process_wizard&feedset=0&shopwizard=bri+codestone&table=shop&criteria=exact&min_price=0&max_price=99999", "http://www.neopets.com/market.phtml?type=wizard")
    2.  
    And finally, let's put the result in our textbox.

    Code (Text):
    1. TextBox3.Text = Response
    Finally, we have a complete working code and it should look like this once finished. I only put the main class since we already saw what the compete coding was in chapter 4.
    Code (Text):
    1.  
    2. Public Class Form1
    3.     Private Wrapper As New TCPWrapper
    4.  
    5.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    6.         Dim Response = Wrapper.NeoLogin(TextBox1.Text, TextBox2.Text, False)
    7.         Label1.Text = Response
    8.     End Sub
    9.  
    10.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    11.         Wrapper.ClearCookies()
    12.     End Sub
    13.  
    14.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    15.         Wrapper.Request("GET", "http://www.neopets.com/market.phtml?type=wizard", "http://www.neopets.com/index.phtml")
    16.         Dim Response = Wrapper.Request("POST", "http://www.neopets.com/market.phtml?type=process_wizard&feedset=0&shopwizard=bri+codestone&table=shop&criteria=exact&min_price=0&max_price=99999", "http://www.neopets.com/market.phtml?type=wizard")
    17.         TextBox3.Text = Response
    18.     End Sub
    19. End Class
    20.  


    The End

    This was just a little example of what can be done with VB.NET. The code was pretty straight foward with no validation but that was not the goal. It will be up to you to code all this. The biggest challenge when coding is to anticipate all the actions of the end-user. I don't want someone clicking something he's not suppose to, and worse, at the wrong time.

    Anyway, I hope this tutorial helped you to understand a little bit more how to program using the HTTPWrapper. The hardest part is getting started. Once you know how it's working, you'll realize it's pretty much the same thing everytime.

    If you have any questions regarding this tutorial or simply some comments, don't hesitate. I'm always ready to help !

    Thanks ! <3
     
    Kaito, Dark, Zer0 and 1 other person like this.
  2. zav75

    zav75 Level I

    Joined:
    Feb 28, 2007
    Messages:
    76
    Likes Received:
    6
    Location:
    Canada, Province of Québec
    Seems like it took a long time to write :D, Well done, I hope people learn from it. I haven't seen any obvious typo.

    Overall it's a nice beginner tutorial, with images and full explanations.
     
    tharoux likes this.
  3. Zer0

    Zer0 Level IV

    Joined:
    Mar 2, 2008
    Messages:
    3,037
    Likes Received:
    180
    Location:
    Home sweet home
    As a suggestion, I would use TamperData for Firefox over a packet editor/sniffer.
    Its more intuitive to use IMO and it logs only HTTP requests coming from your Firefox browser.
     
  4. ceneret0023

    ceneret0023 Level III

    Joined:
    Jun 10, 2007
    Messages:
    663
    Likes Received:
    15
    Location:
    under a rock
    Awesome guide, perfect time to write it too :) i'm gonna try switching from vb6 to vb.net so i can probably pick up even quicker now with the help of this :) also does ether detect do the same thing as live http headers ff add-on?
     
  5. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    Thanks for the input Zer0 !
    I'm not using FF so I'm not to aware of those addon :D

    I guess... regarding addons for FF, maybe you should talk to the one quoted before you ;)
     
  6. Belaarx

    Belaarx Level I

    Joined:
    Sep 23, 2008
    Messages:
    135
    Likes Received:
    16
    Location:
    San Diego
  7. greightone

    greightone Level II

    Joined:
    Jul 8, 2009
    Messages:
    217
    Likes Received:
    1
    What exactly would I type in to pause between sites?
     
  8. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    wrapper.pause(x)
    where x is in second.
     
  9. greightone

    greightone Level II

    Joined:
    Jul 8, 2009
    Messages:
    217
    Likes Received:
    1
    Great. Works perfectly.

    *Edit* Now I just need to figure out how to make the pauses random between a certain amount of seconds.
     
  10. chelsea1

    chelsea1 Level IV

    Joined:
    Nov 26, 2006
    Messages:
    2,538
    Likes Received:
    31
    Location:
    London
    i believe ricky's module has/had a function called "makerandom". i'll see if i can find it for you

    edit: couldn't find it but here is a function which should (i haven't tested) return a random number

    Code (Text):
    1. Public Function RandomNumber(ByVal low As Int32, ByVal high As Int32) As Integer
    2.         Static RandomNumGen As New System.Random
    3.         Return RandomNumGen.Next(low, high+1)
    4.     End Function
     
  11. Richy

    Richy Level IV

    Joined:
    Jul 2, 2007
    Messages:
    1,064
    Likes Received:
    58
    Holy COW! I really hope that whatever went wrong was me...

    I followed this guide, and could understand most of it. I encountered a problem when I tried to run it. My coding all looks like the stuff in your code boxes, but a huge problem occurred. I pressed 'debug' from the menu, then debug from the dropdown. Form1 popped up, and I hit submit. Here's what popped up in that tiny search box:
    HTTP/1.1 302 Found
    Date: Wed, 18 Nov 2009 22:49:46 GMT
    Server: Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7a PHP/5.1.6
    X-Powered-By: PHP/5.1.6
    Set-Cookie: nupi=0; expires=Wed, 18-Nov-2009 21:09:46 GMT; path=/; domain=.neopets.com
    Set-Cookie: nupid=0; expires=Wed, 18-Nov-2009 21:09:46 GMT; path=/; domain=.neopets.com
    Set-Cookie: npid=0; expires=Wed, 18-Nov-2009 21:09:46 GMT; path=/; domain=.neopets.com
    p3p: policy="http://www.neopets.com/privacy.p3p", CP="CURa ADMa DEVa TAIa OUR BUS IND UNI COM NAV INT"
    Location: /loginpage.phtml?destination=%2Fmarket.phtml
    Vary: Accept-Encoding,User-Agent
    Content-Encoding: gzip
    Content-Length: 5057
    Connection: close
    Content-Type: text/html; charset=UTF-8


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <!--
    host - neopets-web-48.811.mtvi.com
    //-->
    <html>
    <head>
    <meta name="description" content="Neopets.Com - Virtual Pet Community! Join up for free games, shops, auctions, chat and more!">
    <meta name="keywords" content="pets, pet, games, game, virtual, chat, fun, prizes, play, virtual pet, kids">
    <meta name="robots" content="noodp, index, follow">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">

    <link rel="stylesheet" type="text/css" href="http://images.neopets.com/css/default.css?v=3">
    <link rel="stylesheet" type="text/css" href="http://images.neopets.com/mamabar/mamabar.css">
    <link rel="stylesheet" type="text/css" href="http://images.neopets.com/css/themes/000_def_f65b1.css?v=4">

    <title>Neopets - Shops owned by the owners of Neopia!</title>

    <script id="js-framework" type="text/javascript" language="JavaScript" src="http://images.neopets.com/js/common.js?v=3"></script>
    <script id="js-browserdetect" type="text/javascript" language="JavaScript" src="http://images.neopets.com/js/getbrowser.js?v=1"></script>
    <script type="text/javascript" src="http://images.neopets.com/n.js"></script> <script type="text/javascript">
    <!--
    var nl = "en";
    var nh = 2;
    var nm = 49;
    var ns = 46;
    var na = "pm";
    var ncl = new Array(0, 53, 104, 137, 169, 198, 231, 265, 299, 335, 368, 397, 427);

    window.setInterval('nc()', 1000);

    function sh(i) {
    ol.style.clip = "rect("+ncl[i-1]+" 128 "+ncl+" 0)";
    ol.style.visibility = "visible";
    }

    function mo() {
    ol.style.visibility = "hidden";
    }

    function search_handle(searchForm) {
    searchForm.action = "/search.phtml";
    searchForm.target = "";
    searchForm.method = "post";
    searchForm.s.value = searchForm.q.value;
    searchForm.submit();
    };
    //-->
    </script>
    <script src="http://images.neopets.com/js/urchin.js" type="text/javascript"></script>
    <script type="text/javascript">
    _uacct = "UA-1152868-1";
    urchinTracker("/market.phtml");
    </script>
    <!-- --></head>
    <body>
    <!-- MAMABAR CODE BLOCK -->
    <script type="text/javascript">
    function brandMamabarMoreOver(el) { el.className = "brand-mamabar-more-link brand-mamabar-more-link-hover"; }
    function brandMamabarMoreOut(el) { el.className = "brand-mamabar-more-link"; }
    </script>
    <div class="brand-mamabar">
    <div class="brand-mamabar-wrapper">
    <ul class="brand-mamabar-list">
    <li><a class="brand-mamabar-active">neopets</a></li>
    <li><a href="http://www.petpetpark.com/">petpet park</a></li>
    <li><a href="http://www.nick.com/">nick</a></li>
    <li><a href="http://www.teenNick.com/">teennick</a></li>
    <li><a href="http://www.shockwave.com/">shockwave</a></li>
    <li class="brand-mamabar-more-link" onmouseover="brandMamabarMoreOver(this);" onmouseout="brandMamabarMoreOut(this);">
    <a class="brand-mamabar-more-a" href="#"><span>more</span></a>
    <div class="brand-mamabar-more-wrapper">
    <ul class="brand-mamabar-more-list">
    <li class="brand-mamabar-first"><a href="http://www.nickjr.com/">nickjr</a></li>
    <li><a href="http://www.addictinggames.com/">addictinggames</a></li>
    <li><a href="http://www.nicktoons.com/">nicktoons</a></li>
    <li><a href="http://www.nickatnite.com/">nick at nite</a></li>
    <li><a href="http://www.upickdaily.com/">upick daily</a></li>
    <li><a href="http://www.parentsconnect.com/">parents connect</a></li>
    <li><a href="http://www.spongebob.com/">spongebob</a></li>
    <li><a href="http://www.icarly.com/">icarly.com</a></li>
    <li><a href="http://www.troopgrid.com/">troopgrid</a></li>
    <li><a href="http://www.quizilla.com/">quizilla</a></li>
    <li><a href="http://www.nickarcade.com/">nick arcade</a></li>
    <li><a href="http://www.nickjrarcade.com/">nickjr arcade</a></li>
    <li class="brand-mamabar-last"><a href="http://www.nickjrboost.com">nickjr boost</a></li>
    </ul>
    </div>
    </li>
    </ul>
    <a class="brand-mamabar-logo" href="http://www.nick.com/"><img alt="Nickelodeon" src="http://images.neopets.com/mamabar/logo_nick_mini.jpg" height="18" width="100"/></a>
    </div>
    </div>
    <div id="main">
    <script type="text/javascript" src="http://images.neopets.com/js/comscore092009.js"></script>
    <script type="text/javascript" src="http://images.neopets.com/js/neoads.js?v=4"></script>
    <div id="ban" style="height: 94px; width: 996px;"><!-- //--> <!-- --><img id='vert_slug_leaderboard' style="position: relative; left: 127px; float: left; " src="http://images.neopets.com/adslug_728.gif" /><!-- Ad object type: xml --><!-- begin ad tag (tile=1) -->


    <script language="JavaScript" type="text/javascript">
    document.write('<script language="JavaScript" src="http://ad.doubleclick.net/adj/neopets.nol/shops/user_shops/atf_adj;sec0=shops;sec1=user_shops;sec2=en;pos=atf;tag=adj;mtype=standard;demo=null;rugrat=null;section_0=shops;section_1=user_shops;hash=2645443197d233cf6ff5e73521cec84f;world=user_shops;u=|sec0-shops|sec1-user_shops|sec2-en|pos-atf|tag-adj|mtype-standard|demo-null|rugrat-null|;tile=1;sz=728x90;ord=8879742601?" type="text/javascript"><\/script>');
    </script>
    <noscript><a href="http://ad.doubleclick.net/jump/neopets.nol/shops/user_shops/atf_adj_standard;sec0=shops;sec1=user_shops;sec2=en;pos=atf;tag=adj;mtype=standard;demo=null;rugrat=null;section_0=shops;section_1=user_shops;hash=2645443197d233cf6ff5e73521cec84f;world=user_shops;u=|sec0-shops|sec1-user_shops|sec2-en|pos-atf|tag-adj|mtype-standard|demo-null|rugrat-null|;tile=1;sz=728x90;ord=8879742601?" target="_blank"><img src="http://ad.doubleclick.net/ad/neopets.nol/shops/user_shops/atf_adj_standard;sec0=shops;sec1=user_shops;sec2=en;pos=atf;tag=adj;mtype=standard;demo=null;rugrat=null;section_0=shops;section_1=user_shops;hash=2645443197d233cf6ff5e73521cec84f;world=user_shops;u=|sec0-shops|sec1-user_shops|sec2-en|pos-atf|tag-adj|mtype-standard|demo-null|rugrat-null|;tile=1;sz=728x90;ord=8879742601?" width="728" height="90" border="0" alt=""></a></noscript>
    <!-- End ad tag -->
    </div> <div id="header">
    <table cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td width="156" height="77" rowspan="3"><a href="/index.phtml"><img src="http://images.neopets.com/transparent_spacer.gif" width="156" height="77" alt="" border="0"></a></td>
    <td class="eventIcon sf" align="left">&nbsp;</td>
    <td class="user medText">
    <a href="/loginpage.phtml"><b>Login to Neopets!</b></a> </td>
    </tr>
    <tr>
    <td colspan="2" id="navigation">
    <table width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td width="725" align="center">
    <script type="text/javascript">
    // Yay for Suckerfish!
    startList = function() {
    if (document.all&&document.getElementById) {
    navRoot = document.getElementById("template_nav");
    for (i=0; i<navRoot.childNodes.length; i++) {
    node = navRoot.childNodes;
    if (node.nodeName=="LI") {
    node.onmouseover=function() {
    this.className+=" over";
    }
    node.onmouseout=function() {
    this.className=this.className.replace(" over", "");
    }
    }
    }
    }
    }
    window.onload=startList;
    </script>

    <ul id="template_nav">
    <li class="nav_image"><a href="/myaccount.phtml"><img src="http://images.neopets.com/themes/000_def_f65b1/navigation/myaccount.png" alt="" border="0" width="119" height="38"></a><ul class="dropdown">
    <li><a href="/myaccount.phtml">&raquo; Control Panel</a></li>
    <li><a href="/preferences.phtml">&raquo; Preferences</a></li>
    <li><a href="/userinfo.phtml">&raquo; Edit Profile</a></li>
    <li><a href="/neomessages.phtml">&raquo; Neomail</a></li>
    <li><a href="/neofriends.phtml">&raquo; Neofriends</a></li>
    <li><a href="/addpet.phtml">&raquo; Create a Neopet</a></li>
    <li><a href="/space/warehouse/prizecodes.phtml">&raquo; Redeem Code</a></li>
    </ul>

    <li class="nav_image"><a href="/customise/"><img src="http://images.neopets.com/themes/000_def_f65b1/navigation/customise.png" alt="" border="0" width="89" height="38"></a><ul class="dropdown">
    <li><a href="/customise/">&raquo; Customise Neopet</a></li>
    <li><a href="/objects.phtml?type=inventory">&raquo; Inventory</a></li>
    <li><a href="/closet.phtml">&raquo; Closet</a></li>
    <li><a href="/neohome/"> &raquo; Neohomes</a></li>
    <li><a href="/neohome/shed">&raquo; Storage Shed</a></li>
    <li><a href="/addpet.phtml">&raquo; Create a Neopet</a></li>
    </ul>
    </li>

    <li class="nav_image"><a href="/games/arcade.phtml"><img src="http://images.neopets.com/themes/000_def_f65b1/navigation/games.png" alt="" border="0" width="66" height="38"></a><ul class="dropdown">
    <li><a href="/games/arcade.phtml">&raquo; Games Room</a></li>
    <li><a href="/games/arcade_more.phtml?cat=top_rated">&raquo; Top Rated</a></li>
    <li><a href="/gamescores.phtml">&raquo; High Scores</a></li>
    <li><a href="/games/favorites.phtml">&raquo; Favourites</a></li>
    <li><a href="/keyquest">&raquo; Key Quest</a></li>
    </ul>
    </li>

    <li class="nav_image"><a href="/explore.phtml"><img src="http://images.neopets.com/themes/000_def_f65b1/navigation/explore.png" alt="" border="0" width="75" height="38"></a><ul class="dropdown">
    <li><a href="/explore.phtml">&raquo; Map of Neopia</a></li>
    <li><a href="/help/tutorial/index.phtml">&raquo; Tutorial</a></li>
    <li><a href="/weather.phtml">&raquo; Weather</a></li>
    <li><a href="/pronounce.phtml">&raquo; Pronunciation</a></li>
    <li><a href="/neopedia.phtml">&raquo; Neopedia</a></li>
    </ul>
    </li>

    <li class="nav_image"><a href="/nf.phtml"><img src="http://images.neopets.com/themes/000_def_f65b1/navigation/news.png" alt="" border="0" width="58" height="38"></a><ul class="dropdown">
    <li><a href="/nf.phtml">&raquo; New Features</a></li>
    <li><a href="/comingsoon.phtml">&raquo; Coming Soon</a></li>
    <li><a href="/ntimes/index.phtml">&raquo; Neopian Times</a></li><li><a href="/stuff.phtml">&raquo; Merch News</a></li> </ul>
    </li>

    <li class="nav_image"><a href="/petcentral.phtml"><img src="http://images.neopets.com/themes/000_def_f65b1/navigation/petcentral.png" alt="" border="0" width="95" height="38"></a><ul class="dropdown">
    <li><a href="/petcentral.phtml">&raquo; Main</a></li>
    <li><a href="/calendar.phtml">&raquo; Calendar</a></li>
    <li><a href="/worldevents.phtml">&raquo; World Events</a></li>
    <li><a href="/pound/index.phtml">&raquo; Neopian Pound</a></li>
    </ul>
    </li>

    <li class="nav_image"><a href="/neoboards/index.phtml"><img src="http://images.neopets.com/themes/000_def_f65b1/navigation/boards.png" alt="" border="0" width="68" height="38"></a><ul class="dropdown">
    <li><a href="/neoboards/index.phtml">&raquo; Neoboard Index</a></li>
    <li><a href="/neoboards/preferences.phtml">&raquo; Preferences</a></li>
    </ul>
    </li>

    <li class="nav_image"><a href="/objects.phtml"><img src="http://images.neopets.com/themes/000_def_f65b1/navigation/shops.png" alt="" border="0" width="62" height="38"></a><ul class="dropdown">
    <li><a href="/objects.phtml">&raquo; Neopia Central</a></li>
    <li><a href="/market.phtml?type=wizard">&raquo; Shop Wizard</a></li>
    <li><a href="/market.phtml?type=your">&raquo; Your Shop</a></li>
    <li><a href="/auctions.phtml">&raquo; Auctions</a></li>
    <li><a href="/island/tradingpost.phtml">&raquo; Trading Post</a></li>
    <li><a href="/bank.phtml">&raquo; Bank</a></li>
    <li><a href="/shopping/index.phtml">&raquo; Merchandise</a></li>
    </ul>
    </li>

    <style type="text/css">
    li.nav_image {
    margin-left: 0px;
    }
    </style>
    <li class="nav_image"><a href="/mall/index.phtml"><img src="http://images.neopets.com/themes/000_def_f65b1/navigation/ncmall.png" alt="" border="0" width="93" height="38"></a><ul class="dropdown">
    <li><a href="/mall/index.phtml">&raquo; Shop</a></li>
    <li><a href="/mall/index.phtml?page=nc">&raquo; Get Neocash</a></li>
    <li><a href="/mall/index.phtml?type=11">&raquo; Neocash Cards</a></li>
    <li><a href="/mall/index.phtml?page=redeem_nc ">&raquo; Redeem Neocash Card</a></li>
    </ul>
    </li>
    </ul>
    </td>
    <td id="nst">2:49:46 pm NST</td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td colspan="3" height="3"><img src="http://images.neopets.com/transparent_spacer.gif" width="1" height="3" alt="" border="0"></td>
    </tr>
    </table>
    </div>

    <div id="content">
    <table width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td align="center" class="sidebar" width="178"><script type='text/javascript' src='http://images.neopets.com/js/swfobject.js?v=2'></script>
    <script type='text/javascript'>
    var swf = new SWFObject('http://images.neopets.com/images/signup_v6.swf', 'flash_97568990881', '160', '600', '8', '#FFFFFF');
    swf.addParam('quality', 'high');
    swf.addParam('scale', 'exactfit');
    swf.addParam('menu', 'false');
    swf.addParam('allowScriptAccess', 'always');
    swf.addParam('swLiveConnect', 'true');
    swf.addParam('wmode', 'transparent');
    swf.addVariable('sURL', '%2Freg%2Findex.phtml%3Fdestination%3D%2Fmarket.phtml');
    swf.addVariable('ilang', 'en');
    swf.write();
    </script>

    <div class="sidebarModule" style="margin-bottom: 7px;">
    <table width="158" cellpadding="2" cellspacing="0" border="0" class="sidebarTable">
    <tr>
    <td valign="middle" class="sidebarHeader medText">Search Neopets</td>
    </tr>
    <tr>
    <td class="neofriend" align="center">
    <form onSubmit="search_handle(this);" style="padding-top: 4px; padding-bottom: 4px;">
    <input class="sf" type="text" name="q" maxlength="255" value="Enter search text..." style="width: 135px; color: #a5a5a5; padding: 2px;" onFocus="this.style.color='#000000'; if( this.value=='Enter search text...' ) { this.value=''; }" onBlur="if( this.value=='' ) { this.style.color='#A5A5A5'; this.value='Enter search text...'; }"><br>
    <input type="submit" value="Go!" class="sf">
    <input type="hidden" name="client" value="pub-9208792519293771">
    <input type="hidden" name="forid" value="1">
    <input type="hidden" name="ie" value="ISO-8859-1">
    <input type="hidden" name="oe" value="ISO-8859-1">
    <input type="hidden" name="safe" value="active">
    <input type="hidden" name="domains" value="www.neopets.com">
    <input type="hidden" name="cof" value="GALT:#FFFFFF;GL:1;DIV:#000066;VLC:FFFFFF;AH:center;BGC:FFFFFF;LBGC:000066;ALC:FFFFFF;LC:FFFFFF;T:000000;GFNT:000066;GIMP:000077;FORID:1">
    <input type="hidden" name="hl" value="en">
    <input type="hidden" name="s">
    </form>
    </td>
    </tr>
    </table>
    </div>
    </td> <td class="content">

    <style type="text/css">
    .bgYellow {
    background-color: #FFCC00;
    }

    .blistHeader {
    background-color: #FFCC00;
    font-weight: bold;
    font-size: 11px;
    color: #000000;
    }

    .blistTopic {
    font-size: 12px;
    }

    .blistSmall {
    font-size: 11px;
    }

    .topicSmall {
    font-weight: normal;
    font-size: 10px;
    }

    .topic {
    background-color: #FFFFFF;
    font-weight: normal;
    font-size: 12px;
    color: #000000;
    border-bottom: 1px solid #000000;
    }

    .topicPosted {
    background-color: #F6F6F6;
    font-weight: normal;
    font-size: 10px;
    color: #000000;
    border-bottom: 1px solid #000000;
    }

    .topicAuthor {
    background-color: #F6F6F6;
    font-weight: normal;

    border-right: 1px solid #000000;
    border-bottom: 1px solid #000000;
    }

    .blockquote {
    margin: 10px;
    }

    .quote {
    background-color: #F6F6F6;
    font-size: 11px;
    font-style: italic;
    border: 1px solid #000000;
    padding: 5px;
    }
    </style>


    <script language="JavaScript">
    var NeoboardPens = {};
    NeoboardPens.maxPostLength = 400;

    function insertSmiley(smiley) {
    document.message_form.message.value += smiley;
    textCounter(document.message_form.message, document.message_form.remLen, NeoboardPens.maxPostLength);
    document.message_form.message.focus();
    return false;
    }

    var submitcount = 0;

    function validateNewTopic() {
    var missing = "";

    if (message_form.topic_title.value == "") { // missing title
    missing += " - Title\n";
    }

    if (message_form.message.value == "") { // if too long...trim it!
    missing += " - Message\n";
    }

    if (missing != "") {
    alert("Please fill in the following item(s):\n" + missing);
    return false;
    } else {
    if (submitcount == 0) {
    submitcount++;
    return true;
    } else {
    alert("Oops, you've already submitted your post.\nPlease wait for it to go through so you don't spam. :)");
    return false;
    }
    }
    }

    function blockMultipleReplies() {
    if (submitcount == 0) {
    submitcount++;
    return true;
    } else {
    alert("Oops, you've already submitted your post.\nPlease wait for it to go through so you don't spam. :)");
    return false;
    }
    }

    function textCounter(field, countfield, maxlimit) {
    maxlimit = maxlimit || NeoboardPens.maxPostLength;
    if (field.value.length > maxlimit) { // if too long...trim it!
    field.value = field.value.substring(0, maxlimit);
    } else { // otherwise, update 'characters left' counter
    countfield.value = maxlimit - field.value.length;
    }
    }

    function openWin(url, height, width, scroll, menu, resize, tool, loc, status) {
    height = (height) ? height : 200;
    width = (width) ? width : 400;
    scroll = (scroll) ? 'yes' : 'no';
    menu = (menu) ? 'yes' : 'no';
    resize = (resize) ? 'yes' : 'no';
    tool = (tool) ? 'yes' : 'no';
    loc = (loc) ? 'yes' : 'no';
    status = (status) ? 'yes' : 'no';
    options = 'scrollbars='+scroll+',menubar='+menu+',height='+height+',width='+width+',resizable='+resize+',toolbar='+tool+',location='+loc+',status='+status;
    if (url) {
    var load = window.open(url,'', options);
    }
    }
    </script>


    I'm afraid I don't understand a whole lot of that XD could you tell me where I went wrong? Pretty please?

    Also, here's my entire code:
    Imports System.Net
    Imports System.Text.RegularExpressions
    Imports System.IO
    Imports System.Text
    Imports System.IO.Compression

    Public Class Form1
    Private Wrapper As New TCPWrapper

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Response = Wrapper.NeoLogin(TextBox1.Text, TextBox2.Text, False)
    Label1.Text = Response
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Wrapper.ClearCookies()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Wrapper.Request("GET", "http://www.neopets.com/market.phtml?type=wizard", "http://www.neopets.com/index.phtml")
    Dim Response = Wrapper.Request("POST", "http://www.neopets.com/market.phtml?type=process_wizard&feedset=0&shopwizard=bri+codestone&table=shop&criteria=exact&min_price=0&max_price=99999", "http://www.neopets.com/market.phtml?type=wizard")
    TextBox3.Text = Response
    End Sub
    End Class

    Public Class TCPWrapper
    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()
    components = New System.ComponentModel.Container
    End Sub
    #End Region
    Private colCookies As New Collection
    Dim strCookies As String
    Public LastPage As String
    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 strPost 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
    If Method = "POST2" Then
    pos = strFile.IndexOf("?")
    If Not (pos = -1) Then
    strPost = strFile.Substring(pos + 1)
    strFile = strFile.Substring(0, pos)
    Else
    strPost = ""
    End If
    End If
    LastPage = URL
    Dim ReqHeaders As String = Nothing
    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 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & 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 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & 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: " + strPost.Length.ToString + "" & 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)
    LastPage = URL
    Try
    tcp.Connect(Host, 80)
    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)
    Return strParts(1)
    End Function
    Public Function NeoLogin(ByVal user As String, ByVal pass As String, ByRef loggedIn As Boolean) As String
    Dim strHTML As String = Nothing
    Request("GET", "http://www.neopets.com/loginpage.phtml", "http://www.google.com")
    Pause(1)
    Request("POST", "http://www.neopets.com/hi.phtml?destination=%2Findex.phtml&username=" + user, "http://www.neopets.com/loginpage.phtml")
    Pause(1)
    strHTML = Request("POST", "http://www.neopets.com/login.phtml?username=" + user + "&password=" + pass + "&destination=%2Findex.phtml", "http://www.neopets.com/hi.phtml")
    If strHTML.Contains("Set-Cookie: neologin=") Then
    loggedIn = True
    Return "Logged In"
    Else
    If strHTML.Contains("too many times") Then
    loggedIn = False
    Return "To Many Login Attempts"
    Else
    If strHTML.Contains("badpassword") Then
    loggedIn = False
    Return "Wrong Username/Password"
    Else
    If strHTML.Contains("frozen") Then
    loggedIn = False
    Return "Account Frozen"
    Else
    If strHTML.Contains("just a technical problem") Then
    loggedIn = False
    Return "Neopets is down for maintenance"
    Else
    loggedIn = False
    Return "Unknow Error"
    End If
    End If
    End If
    End If
    End If
    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
    Public Function GetBetween(ByVal Source As String, ByVal Start As String, ByVal Finish As String) As String
    Dim Result = ""
    Dim A = InStr(1, Source, Start) + Len(Start)
    If A = 0 Then
    Result = ""
    Return Result
    Else
    Dim B = InStr(A, Source, Finish)
    If B = 0 Then
    Result = ""
    Return Result
    Else
    Result = Mid(Source, A, B - A)
    Return Result
    End If
    End If
    End Function
    End Class
     
  12. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    I'm glad you tried this tutorial :p

    First, I just want to clear something. The code you got after clicking "search" is the kind of code you'll receive everytime. In fact, that simply the source code of the web page. If you take all this code and put it in an HTML file and open it, you'll see the page just like you can in your browser. This beeing said, your code is perfectly fine. The reason you didn't receive the proper SW code with the "bri codestone" price is simply because you weren't logged in to neopets.com in the program.

    Try to log, then wait for the message "logged in" and then press the "search" button to receive the information. The code will look pretty similar to the one posted here but will contains the precious data we need to go on after.

    If you have any more question, lemme know ;)
     
  13. Richy

    Richy Level IV

    Joined:
    Jul 2, 2007
    Messages:
    1,064
    Likes Received:
    58
    Another question... how do I open my saved project? a wee bit embarrassing, but I don't know how lol.

    I saved it as 'Bri Codestone' to my desktop. Three icons appeared... clicking any of them will only bring up the code or an error saying it doesn't know what program to use
     
  14. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    you have to open the file ending by ".sln"
     
  15. Richy

    Richy Level IV

    Joined:
    Jul 2, 2007
    Messages:
    1,064
    Likes Received:
    58
    *grumbles* I hate file endings. Thank you for the help, but I've decided to just re-do the whole thing this weekend, and I'll also take a look at opening projects this weekend lol
     
  16. Violent_J

    Violent_J Level I

    Joined:
    Oct 21, 2008
    Messages:
    41
    Likes Received:
    1
    Keep getting

    "Class must end with matching end class"
     
  17. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    You're missing "End Class" at the end of the class.
    You probably erased it by mistake.

    Or simply send me the zipped project by pm, I'll take a look :)
     
  18. Violent_J

    Violent_J Level I

    Joined:
    Oct 21, 2008
    Messages:
    41
    Likes Received:
    1
    You mean like end sub in vb6?

    Well, the wrapper does have "end class" at the end of it.
     
  19. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    Yep, you need it at the end.
    Btw, I checked the wrapper class in the first post and the "End Class" is there ;)
    Code (Text):
    1. Class
    2.  sub
    3.  end sub
    4.  
    5.  sub
    6.  end sub
    7. end class
     
  20. Violent_J

    Violent_J Level I

    Joined:
    Oct 21, 2008
    Messages:
    41
    Likes Received:
    1
    Well, I changed this

    Public Class Form1
    Private Wrapper As New TCPWrapper

    To

    Public Class VJUG

    Private W As New TCPWrapper

    Of course I switch the name wrapper with w everywhere else. xD

    VJUG = Violent_'s Username Grabber