|
-
Jan 18th, 2007, 08:30 AM
#1
Thread Starter
New Member
[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:
Dim down As New Net.WebClient
down.Headers.Set(Net.HttpRequestHeader.Host, "www.hrt.hr")
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")
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")
down.Headers.Set(Net.HttpRequestHeader.AcceptLanguage, "en-us,en;q=0.5")
down.Headers.Set(Net.HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
down.Headers.Set(Net.HttpRequestHeader.KeepAlive, "300")
down.Headers.Set(Net.HttpRequestHeader.Connection, "keep-alive")
down.Headers.Set(Net.HttpRequestHeader.Referer, "http://www.vb.bloger.hr/")
down.Headers.Set(Net.HttpRequestHeader.Pragma, "no-cache")
down.Headers.Set(Net.HttpRequestHeader.CacheControl, "no-cache")
down.DownloadFile("http://www.hrt.hr/index.xml", "C:\Downloads\test1.txt")
I also tried with:
But non of them work.
Please help.
Last edited by tomoslav; Feb 9th, 2007 at 05:10 PM.
-
Jan 18th, 2007, 06:03 PM
#2
Re: [2005] Download file - specific headers
use the HttpWebRequest method, eg:
VB Code:
[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)
request.Method = [COLOR=Purple]"GET"[/COLOR]
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]
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]
request.Headers.Add(HttpRequestHeader.AcceptLanguage, [COLOR=Purple]"en-us,en;q=0.5"[/COLOR])
request.Headers.Add(HttpRequestHeader.AcceptCharset, [COLOR=Purple]"ISO-8859-1,utf-8;q=0.7,*;q=0.7"[/COLOR])
request.KeepAlive = [COLOR=Blue]True[/COLOR]
request.Referer = [COLOR=Purple]"http://www.vb.bloger.hr/"[/COLOR]
request.Headers.Add(HttpRequestHeader.Pragma, [COLOR=Purple]"no-cache"[/COLOR])
request.Headers.Add(HttpRequestHeader.CacheControl, [COLOR=Purple]"no-cache"[/COLOR])
[COLOR=Blue]Dim[/COLOR] response [COLOR=Blue]As[/COLOR] HttpWebResponse = [COLOR=Blue]DirectCast[/COLOR](request.GetResponse, HttpWebResponse)
[COLOR=Blue]Dim[/COLOR] sreader [COLOR=Blue]As New[/COLOR] StreamReader(response.GetResponseStream, System.Text.Encoding.Default)
[COLOR=Blue]Dim[/COLOR] swriter [COLOR=Blue]As New[/COLOR] StreamWriter([COLOR=Purple]"C:\Downloads\test1.txt"[/COLOR], [COLOR=Blue]False[/COLOR])
swriter.Write(sreader.ReadToEnd)
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]
-
Jan 19th, 2007, 07:54 AM
#3
Thread Starter
New Member
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.
-
Jan 19th, 2007, 08:04 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|