"An invalid argument was supplied" can someone help me out?
"An invalid argument was supplied" can someone help me out?
"An invalid argument was supplied" can someone help me out?
"An invalid argument was supplied" can someone help me out?
"An invalid argument was supplied" can someone help me out?
"An invalid argument was supplied" can someone help me out? "An invalid argument was supplied" can someone help me out? "An invalid argument was supplied" can someone help me out? "An invalid argument was supplied" can someone help me out? "An invalid argument was supplied" can someone help me out? "An invalid argument was supplied" can someone help me out? "An invalid argument was supplied" can someone help me out? "An invalid argument was supplied" can someone help me out?
"An invalid argument was supplied" can someone help me out? "An invalid argument was supplied" can someone help me out?
"An invalid argument was supplied" can someone help me out?
Go Back  Xtreme Visual Basic Talk > > > "An invalid argument was supplied" can someone help me out?


Reply
 
Thread Tools Display Modes
  #1  
Old 05-15-2006, 01:54 PM
NeoSaint NeoSaint is offline
Regular
 
Join Date: Mar 2006
Posts: 71
Default "An invalid argument was supplied" can someone help me out?


I have this class here
and i'm trying to connect to a website and I keep getting "An invalid argument was supplied"
can someone fix my code or tell me what I'm doing wrong?
Code:
Imports System.Text.Regularexpressions Public Class MySock 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, Optional ByVal Referer As String = "") As String Dim tcp As New System.Net.Sockets.TcpClient Dim netstream As System.Net.Sockets.NetworkStream Dim Host As String, TN(1) As Long If Referer = "" Then Referer = LastPage If InStr(1, URL, "http://") Then Host = Mid(URL, 8) End If If InStr(1, URL, "/") Then TN(0) = InStr(1, URL, "/") Host = Mid(URL, 1, TN(0) - 1) End If LastPage = URL Try tcp.Connect(Host, 80) Catch ex As Exception Return ex.Message End Try Dim sendbytes As Byte(), ReqHeaders As String ReqHeaders = SortHeaders(Method, URL, Referer) sendbytes = System.Text.Encoding.ASCII.GetBytes(ReqHeaders) MsgBox(ReqHeaders) netstream = tcp.GetStream() netstream.Write(sendbytes, 0, sendbytes.Length) tcp.ReceiveBufferSize = 1048576 Dim recv(tcp.ReceiveBufferSize) As Byte netstream.Read(recv, 0, CInt(tcp.ReceiveBufferSize)) Dim out As String out = System.Text.Encoding.UTF8.GetString(recv) strCookies = ParseCookies(out.ToString) Return out End Function Private Function SortHeaders(ByVal Method As String, ByVal URL As String, ByVal Referer As String) Dim Host As String, URI As String, tn(1) As Integer, PostData As String If InStr(1, URL, "/") Then tn(0) = InStr(1, URL, "/") Host = Mid(URL, 1, tn(0) - 1) URI = Mid(URL, tn(0)) If InStr(1, URI, "?") Then tn(1) = InStr(1, URI, "?") URI = Mid(URI, 1, tn(1) - 1) End If End If If InStr(1, URL, "?") And Method = "POST" Then tn(0) = InStr(1, URL, "?") + 1 PostData = Mid(URL, tn(0)) End If Select Case Method Case "POST" SortHeaders = "POST " & URI & " HTTP/1.0" & ControlChars.CrLf & _ "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*" & ControlChars.CrLf & _ "Referer: " & Referer & ControlChars.CrLf & _ "Accept-Language: en-gb" & ControlChars.CrLf & _ "Content-Type: application/x-www-form-urlencoded" & ControlChars.CrLf & _ "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6" & ControlChars.CrLf & _ "Host: " & Host & ControlChars.CrLf & _ "Content-Length: " & Len(PostData).ToString & ControlChars.CrLf & _ "Pragma: no-cache" & ControlChars.CrLf & _ "Cookie: " & strCookies & ControlChars.CrLf & _ ControlChars.CrLf & _ PostData & ControlChars.CrLf Case Else SortHeaders = Method & " " & URI & " HTTP/1.0" & ControlChars.CrLf & _ "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*" & ControlChars.CrLf & _ "Referer: " & Referer & ControlChars.CrLf & _ "Accept-Language: en-gb" & ControlChars.CrLf & _ "Content-Type: application/x-www-form-urlencoded" & ControlChars.CrLf & _ "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6" & ControlChars.CrLf & _ "Host: " & Host & ControlChars.CrLf & _ "Connection: Keep-Alive" & ControlChars.CrLf & _ "Cookie: " & strCookies & _ ControlChars.CrLf & ControlChars.CrLf End Select End Function Public Function ParseCookies(ByVal Headers As String) 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 End Class
Reply With Quote
Reply


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

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
&quot;An invalid argument was supplied&quot; can someone help me out?
&quot;An invalid argument was supplied&quot; can someone help me out?
&quot;An invalid argument was supplied&quot; can someone help me out? &quot;An invalid argument was supplied&quot; can someone help me out?
&quot;An invalid argument was supplied&quot; can someone help me out?
&quot;An invalid argument was supplied&quot; can someone help me out?
&quot;An invalid argument was supplied&quot; can someone help me out? &quot;An invalid argument was supplied&quot; can someone help me out? &quot;An invalid argument was supplied&quot; can someone help me out? &quot;An invalid argument was supplied&quot; can someone help me out? &quot;An invalid argument was supplied&quot; can someone help me out? &quot;An invalid argument was supplied&quot; can someone help me out? &quot;An invalid argument was supplied&quot; can someone help me out?
&quot;An invalid argument was supplied&quot; can someone help me out?
&quot;An invalid argument was supplied&quot; can someone help me out?
 
&quot;An invalid argument was supplied&quot; can someone help me out?
&quot;An invalid argument was supplied&quot; can someone help me out?
 
-->