ok i put mystical's neopets login into my code and its all in there properly with no errors before executing the program but when i execute it and click my login button i get this error: on this line: Code (Text): 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 can anyone help?
Not sure why that is but since then mystical has updated the wrapper and also I've updated it a bit so here's the updated version which you should try.. Obviously you'll need to change some of the names... Code (Text): 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 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 bGzip As Boolean 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 LastPage = URL Dim ReqHeaders As String = Nothing If bGzip = True Then 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 Else 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-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-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 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 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 Dim uppBound As Integer = strParts.GetUpperBound(0) Dim strReturn As String = "" For i As Integer = 1 To uppBound strReturn += strParts(i) Next If InStr(strReturn, "aisha_signup.gif") Then If frmMain.chkWarn.Checked = False Then frmMain.TimerAutobuy.Enabled = False frmMain.lblStatus.Text = "Logged out!" frmMain.GroupBox1.Enabled = True frmMain.cmdLogout.Enabled = False frmMain.cmdLogin.Enabled = True frmMain.cmdStop.Enabled = False frmMain.cmdStart.Enabled = True MsgBox("You have been logged out!", MsgBoxStyle.Critical, "Logged out!") ClearCookies() Else frmMain.lblStatus.Text = "Logged out!" frmMain.TimerAutobuy.Enabled = False ClearCookies() Pause(5) frmMain.Login(frmMain.txtUsername.Text, frmMain.txtPassword.Text) Pause(5) frmMain.lblStatus.Text = "Looking for Items" frmMain.TimerAutobuy.Enabled = True frmMain.cmdStop.Enabled = True frmMain.cmdStart.Enabled = False End If End If Return strReturn 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 ClearCookies() Dim strHTML As String = Nothing Request("GET", "http://neopets.com/loginpage.phtml", "http://google.com") Pause(1) Request("POST", "http://www.neopets.com/hi.phtml?destination=%2Fpetcentral.phtml&username=" + user, "http://neopets.com/loginpage.phtml") Pause(1) Request("POST", "http://www.neopets.com/login.phtml?username=" + user + "&password=" + pass + "&destination=%2Fpetcentral.phtml", "http://neopets.com/hi.phtml") strHTML = Request("GET", "http://www.neopets.com/objects.phtml", "http://www.neopets.com/petcentral.phtml") If strHTML.Contains("Welcome,") 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("not logged in") Then loggedIn = False Return "Wrong 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 strHTML 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 Function DownloadImage(ByVal URL As String) As System.Drawing.Image Dim imageFile As New WebClient Dim bytes() As Byte = imageFile.DownloadData(URL) Dim imageStream As New MemoryStream(bytes) Dim downloadedImage As System.Drawing.Image = Image.FromStream(imageStream) DownloadImage = downloadedImage End Function Public Sub ClearCookies() colCookies.Clear() strCookies = Nothing End Sub Public Function GetCookie() Return strCookies End Function End Class