Results 1 to 4 of 4

Thread: [2005] Download file - specific headers

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Location
    Croatia~Zagreb
    Posts
    5

    Resolved [2005] Download file - specific headers

    I need help downloading file, for example http://www.hrt.hr/index.xml
    But I need that headers to look like these:


    GET /index.xml HTTP/1.1
    Host: www.hrt.hr
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
    Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    Accept-Language: en-us,en;q=0.5
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive
    Referer: http://vb.bloger.hr/
    Pragma: no-cache
    Cache-Control: no-cache


    I have tried this:
    VB Code:
    1. Dim down As New Net.WebClient
    2.         down.Headers.Set(Net.HttpRequestHeader.Host, "www.hrt.hr")
    3.         down.Headers.Set(Net.HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1")
    4.         down.Headers.Set(Net.HttpRequestHeader.Accept, "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5")
    5.         down.Headers.Set(Net.HttpRequestHeader.AcceptLanguage, "en-us,en;q=0.5")
    6.         down.Headers.Set(Net.HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
    7.         down.Headers.Set(Net.HttpRequestHeader.KeepAlive, "300")
    8.         down.Headers.Set(Net.HttpRequestHeader.Connection, "keep-alive")
    9.         down.Headers.Set(Net.HttpRequestHeader.Referer, "http://www.vb.bloger.hr/")
    10.         down.Headers.Set(Net.HttpRequestHeader.Pragma, "no-cache")
    11.         down.Headers.Set(Net.HttpRequestHeader.CacheControl, "no-cache")
    12.         down.DownloadFile("http://www.hrt.hr/index.xml", "C:\Downloads\test1.txt")

    I also tried with:
    VB Code:
    1. down.Headers.Add
    But non of them work.

    Please help.
    Last edited by tomoslav; Feb 9th, 2007 at 05:10 PM.

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: [2005] Download file - specific headers

    use the HttpWebRequest method, eg:
    VB Code:
    1. [COLOR=Blue]Dim[/COLOR] request [COLOR=Blue]As[/COLOR] HttpWebRequest = [COLOR=Blue]DirectCast[/COLOR](HttpWebRequest.Create([COLOR=Purple]"http://www.hrt.hr/index.xml"[/COLOR]), HttpWebRequest)
    2.  
    3.         request.Method = [COLOR=Purple]"GET"[/COLOR]
    4.         request.UserAgent = [COLOR=Purple]"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"[/COLOR]
    5.         request.Accept = [COLOR=Purple]"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"[/COLOR]
    6.         request.Headers.Add(HttpRequestHeader.AcceptLanguage, [COLOR=Purple]"en-us,en;q=0.5"[/COLOR])
    7.         request.Headers.Add(HttpRequestHeader.AcceptCharset, [COLOR=Purple]"ISO-8859-1,utf-8;q=0.7,*;q=0.7"[/COLOR])
    8.         request.KeepAlive = [COLOR=Blue]True[/COLOR]
    9.         request.Referer = [COLOR=Purple]"http://www.vb.bloger.hr/"[/COLOR]
    10.         request.Headers.Add(HttpRequestHeader.Pragma, [COLOR=Purple]"no-cache"[/COLOR])
    11.         request.Headers.Add(HttpRequestHeader.CacheControl, [COLOR=Purple]"no-cache"[/COLOR])
    12.  
    13.         [COLOR=Blue]Dim[/COLOR] response [COLOR=Blue]As[/COLOR] HttpWebResponse = [COLOR=Blue]DirectCast[/COLOR](request.GetResponse, HttpWebResponse)
    14.  
    15.         [COLOR=Blue]Dim[/COLOR] sreader [COLOR=Blue]As New[/COLOR] StreamReader(response.GetResponseStream, System.Text.Encoding.Default)
    16.         [COLOR=Blue]Dim[/COLOR] swriter [COLOR=Blue]As New[/COLOR] StreamWriter([COLOR=Purple]"C:\Downloads\test1.txt"[/COLOR], [COLOR=Blue]False[/COLOR])
    17.  
    18.         swriter.Write(sreader.ReadToEnd)
    19.  
    20.         response.Close()
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Location
    Croatia~Zagreb
    Posts
    5

    Re: [2005] Download file - specific headers

    I get error when I run program.
    Here is screenshot.
    Please help.
    http://img228.imageshack.us/img228/7911/errorcf0.jpg

    EDIT: It's now working good. I don't know why didn't it work before.
    Last edited by tomoslav; Feb 9th, 2007 at 05:11 PM.

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: [2005] Download file - specific headers

    works ok from where i am, it opens some site to do with croatian television.
    are you sure you aint got a firewall blocking your app?
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width