Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过http登录并下载xml文件?_C#_Http_Authentication_Httpwebrequest_Web Scraping - Fatal编程技术网

C# 通过http登录并下载xml文件?

C# 通过http登录并下载xml文件?,c#,http,authentication,httpwebrequest,web-scraping,C#,Http,Authentication,Httpwebrequest,Web Scraping,需要从以下url登录并下载xml文件: 我已经知道如何使用WebClient HttpWebRequest获取和发布数据。但是对于上面的url,我根本不知道该怎么做 我尝试对上面的Url使用Live Http头。它显示了如下内容: http://www.radionyhetene.net/download/nyheter/mp3/nyheter.xml GET /download/nyheter/mp3/nyheter.xml HTTP/1.1 Host: www.radionyhetene.

需要从以下url登录并下载xml文件:

我已经知道如何使用WebClient HttpWebRequest获取和发布数据。但是对于上面的url,我根本不知道该怎么做

我尝试对上面的Url使用Live Http头。它显示了如下内容:

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
所以问题是如何将登录信息传递到此url?请提供您的建议。 谢谢。

简单

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


的确,谢谢你的时间和建议:)的确,谢谢你的时间和建议:)