2012-03-30 35 views
0

需要登錄,並從以下網址下載xml文件:通過http登錄並下載一個xml文件?

http://www.radionyhetene.net/download/nyheter/mp3/nyheter.xml

我已經知道如何使用Web客戶端,HttpWebRequest的。但對於上面的URL GET和POST數據,我不是在所有能明白該怎麼做。

我嘗試使用Live Http Header作爲上述Url。它顯示了這樣的事情:

http://www.radionyhetene.net/download/nyheter/mp3/nyheter.xml 
GET /download/nyheter/mp3/nyheter.xml HTTP/1.1 
Host: www.radionyhetene.net 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115    Firefox/3.6 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
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: 115 
Connection: keep-alive 
Authorization: Basic aGF1Z2FsYW5kOjlmNm5kOGtmMw== 

HTTP/1.1 200 OK 
Date: Fri, 30 Mar 2012 16:09:35 GMT 
Server: Apache/2.2.15 (Win32) PHP/5.3.2 
Last-Modified: Fri, 30 Mar 2012 14:54:13 GMT 
Etag: "4730000000053f1-194-4bc77038957a2" 
Accept-Ranges: bytes 
Content-Length: 404 
Keep-Alive: timeout=5, max=100 
Connection: Keep-Alive 
Content-Type: application/xml 

所以問題是我該如何傳遞登錄信息到這個網址?請提供您的建議。 謝謝。

回答

3

簡單,

WebClient web = new WebClient(); 
web.Credentials = new NetworkCredential("h.....", "9......."); 
string s = web.DownloadString("http://www.radionyhetene.net/download/nyheter/mp3/nyheter.xml"); 
+0

事實上,感謝您的時間和建議:) – Muse 2012-03-30 16:36:50