Question HttpWebRequest - can you notice what I am doing wrong?

Cheetah

Well-known member
Joined
Oct 12, 2006
Messages
232
Programming Experience
Beginner
Hi there,

I am following this guide here to download a video via a web request: linky!

But I get an error in the headers instead of a redirect and I'm assuming i am doing something wrong.

What I should be getting is a message box of a header which has a redirect in it. I have checked and the header data i start with is not incorrect, as far as i can see.

Here is my code:

VB.NET:
Imports System.Net
Imports System.Text.RegularExpressions

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        GetVideoLink("b00c0cd1")

    End Sub

    Private Sub GetVideoLink(ByVal ProgramID As String)

        Dim WebRequest1 As HttpWebRequest = WebRequest.Create("http://www.bbc.co.uk/iplayer/page/item/" & ProgramID & ".shtml")
        WebRequest1.UserAgent = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3"

        Dim WebResponse1 As HttpWebResponse = WebRequest1.GetResponse()

        Dim CookieData As String = Regex.Match(WebResponse1.Headers.ToString(), "Set-Cookie: (.+?);").Groups(1).Value.ToString()

        WebResponse1.Close()

        Dim rnd As Random = New Random()

        Dim WebRequest2 As HttpWebRequest = WebRequest.Create("http://www.bbc.co.uk/mediaselector/3/auth/iplayer_streaming_http_mp4/" & ProgramID & "?" & rnd.Next(0, 1000000).ToString())
        WebRequest2.AllowAutoRedirect = False
        WebRequest2.Accept = "*/*"
        WebRequest2.Headers.Set(HttpRequestHeader.Cookie, CookieData)
        WebRequest2.UserAgent = "Apple iPhone v1.1.4 CoreMedia v1.0.0.4A102"
        WebRequest2.KeepAlive = False
        WebRequest2.AddRange(0, 1)

        Dim WebResponse2 As HttpWebResponse = WebRequest2.GetResponse()

        MessageBox.Show(WebResponse2.Headers.ToString())

        WebResponse2.Close()

    End Sub

End Class

Thanks.
 
Back
Top