Question Need help wit Net.WebClient

ecoster

Member
Joined
Sep 11, 2011
Messages
6
Programming Experience
1-3
Hello people from VB.NET Forums.

I made a app that worked perfectly for years, but now there has been a change in something and it's not working properly any more.

It's used to get torrent links from ThePiratebay. you can get the top 100, that still works but when I want to search for a torrent I keep getting 0 back:(
EasyCapture2.jpg
EasyCapture3.jpg

Search for links(not working any more)
VB.NET:
Private Sub VideoMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VideoMenu.Click
        Dim theItem As String
        Dim wb As New Net.WebClient
        Dim src As String

        theItem = InputBox("Type in the name of the Video file you want to find.", " Video search")
        If theItem = "" Then Exit Sub

        Me.Cursor = Cursors.WaitCursor
        TorrentList.Items.Clear()
        src = wb.DownloadString("http://thepiratebay.org/search/" + (theItem) + "/0/7/200")
        TabPage1.Text = (GetLinks(src) & " Torrents found")

        Me.Cursor = Cursors.Default
    End Sub

Top100(works)
VB.NET:
Private Sub Top100MoviesMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Top100MoviesMenu.Click
        Dim wb As New Net.WebClient
        Dim src As String
        Me.Cursor = Cursors.WaitCursor
        TorrentList.Items.Clear()
        TextBox1.Clear()
        src = wb.DownloadString("http://thepiratebay.org/top/201")
        TabPage1.Text = (GetLinks(src) & " Torrents found.")
        Me.Cursor = Cursors.Default
    End Sub

VB.NET:
Private Function GetLinks(ByRef HTML As String) As Long
        Dim lonRet As Long, lonStart As Long
        Dim lonEnd As Long

        TorrentList.Items.Clear()
        lonRet = -1
        Do
            lonStart = InStr(lonStart + 1, HTML, "http://torrents.thepiratebay.org", vbTextCompare)
            If lonStart > 0 Then
                lonStart = lonStart + 0

                lonEnd = InStr(lonStart, HTML, """", CompareMethod.Text)
                If lonEnd > 0 Then
                    lonRet = lonRet + 1

                    TorrentList.Items.Add(Mid$(HTML, lonStart, lonEnd - lonStart))
                    lonStart = lonEnd
                End If
            End If
        Loop Until lonStart = 0
        Return lonRet + 1
    End Function

It seems to be in the Url's but I can't figure it out.
If I type in my browser "http://thepiratebay.org/search/Hulk/0/7/200" I get the links, but somehow this "http://thepiratebay.org/search/" + (theItem) + "/0/7/200" isn't getting anything back in the app.

Thanks in advance,
ecoster

Ps,
I apologise if this isn't in the correct section.
 

Attachments

  • EasyCapture1.jpg
    EasyCapture1.jpg
    17.6 KB · Views: 29
You can debug actual browser requests and responses with tools such as Fiddler.
The most common reason is that the server will not serve unless at least UserAgent header is set, for example:
wb.Headers(System.Net.HttpRequestHeader.UserAgent) = "Custom Agent"
 
Thanks for the quick reply and pointing me to a new tool to use, but how do I implement this in the code above.
I really have no clue where to start.
 
Let's see, you have three parts, here as an unordered list:
  • use webclient
  • create webclient
  • configure webclient
Now, what would the correct order of these three parts be?
 
Back
Top