问题
Need to login and download xml file from the below url :
http://www.radionyhetene.net/download/nyheter/mp3/nyheter.xml
I already know how to get and post data using WebClient ,HttpWebRequest .But for the above url ,I am not at all able to understand what to do .
I tried using Live Http Header for the above Url . It shows something like this :
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
So the question is how can I pass login information to this url ? Kindly provide your suggestion regarding. Thanks.
回答1:
Easy,
WebClient web = new WebClient();
web.Credentials = new NetworkCredential("h.....", "9.......");
string s = web.DownloadString("http://www.radionyhetene.net/download/nyheter/mp3/nyheter.xml");
来源:https://stackoverflow.com/questions/9946816/login-and-download-an-xml-file-over-http