frankweerasinghe
Power Member
- Jun 6, 2011
- 555
- 430
I have a public function to get the pagesource of web URLs. Here is the function.
The problem is it works fine with first call like
But after that, it doesn't use the proxy I provide to it. it simply uses the same proxy used in the 1st request. I'm calling this function using a thread because if I use this on main thread I'll freeze the UI. What I'm doing wrong? I'm a noob in VB.net
Thanks.
Code:
Public Function gethtml(ByVal id As Integer)
Try
ListView1.Items(id).SubItems(6).Text = "Downloading HTML..."
Dim Response3 As HttpWebResponse
Dim pagesource3 As String
Dim datastream As Stream
Dim postdata As String = ""
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postdata)
Dim Request3 As HttpWebRequest = HttpWebRequest.Create("http://mysite.com/ip.php")
Request3.Referer = "http://google.com/"
Request3.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
Request3.KeepAlive = True
Request3.Timeout = "5000"
Request3.AllowAutoRedirect = True
If useproxycheckbox.Checked = True Then
Dim words As String() = ListView1.Items(id).SubItems(9).Text.Split(New Char() {":"c})
Request3.Proxy = New WebProxy(words(0).ToString & ":" & words(1).ToString)
Request3.UseDefaultCredentials = False
Request3.Proxy.Credentials = New System.Net.NetworkCredential(words(2).ToString, words(3).ToString)
End If
Request3.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31"
Request3.CookieContainer = CC
Request3.Method = WebRequestMethods.Http.Get
Request3.ContentType = "application/x-www-form-urlencoded"
Response3 = Request3.GetResponse()
Dim Stream3 As New StreamReader(Response3.GetResponseStream())
pagesource3 = Stream3.ReadToEnd()
Response3.Close()
Stream3.Close()
ListView1.Items(id).SubItems(4).Text = pagesource3
Catch e1 As ProtocolViolationException
recheck(id)
ListView1.Items(id).SubItems(6).Text = "Error1"
Catch e2 As WebException
recheck(id)
ListView1.Items(id).SubItems(6).Text = "Error2"
End Try
End Function
The problem is it works fine with first call like
Code:
gethtml(0)
But after that, it doesn't use the proxy I provide to it. it simply uses the same proxy used in the 1st request. I'm calling this function using a thread because if I use this on main thread I'll freeze the UI. What I'm doing wrong? I'm a noob in VB.net
Thanks.