Little help from .NET Programmers please....

cheetah05

Portal Pro
April 9, 2006
328
18
London
Basically i am trying to create a MP plugin to accommodate BBC iPlayer, then download and viewing of the higher quality x264 encodes.

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.

I am working in C#, but rewrote it in VB as there is more chance of getting a response that way as VB programmers can try.......

If you are going to try out the code, you need to be from the UK as BBC only lets UK viewers watch the streams. I was hoping people could notice what was wrong without actually running the code though.

Code:
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.
 

cheetah05

Portal Pro
April 9, 2006
328
18
London
404 to a bbc error page which says the programme doesn't exist - I have tried it with alot of programmes, all of them give the same response.

I'm assuming there is something wrong with the way i made the request, maybe i didn't follow the tutorial correctly.
 

jburnette

Portal Pro
August 24, 2006
758
43
Kentucky
Have you actually watched the traffic with something like WireShark to make sure you're correctly replicating a browser? I realize that your code looks correct, but perhaps their server is very picky about your headers (or something else, for that matter).
 

cheetah05

Portal Pro
April 9, 2006
328
18
London
Have you actually watched the traffic with something like WireShark to make sure you're correctly replicating a browser? I realize that your code looks correct, but perhaps their server is very picky about your headers (or something else, for that matter).
I haven't no.....what does WireShark actually do? I swear i have used the program before and all it did was show packets of data being transferred as bytes?

The only thing i think it could be possibly is the fact that i haven't got the "Connection: close" header (which i don't know how to set).....or the headers are in the wrong order. (just noticed both these things now)
 

jburnette

Portal Pro
August 24, 2006
758
43
Kentucky
Wireshark is just a packet sniffer. It's very useful in a situation like this, though, for actually seeing the raw requests/responses you're sending/receiving. Might shed a little more light on what's going on.
 
Top Bottom