尝试这个
string sVal = "http://www.w3schools.com/xml/note.xml";
XDocument document = XDocument.Load(sVal);
或者
Uri url = new Uri("http://www.w3schools.com/xml/note.xml");
using (var wc = new WebClient())
{
string sss = wc.DownloadString(url);
}
如果您面临安全问题
尝试这个
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "GET";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
// allows for validation of SSL conversations
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
WebResponse respon = req.GetResponse();
Stream res = respon.GetResponseStream();
string ret = "";
byte[] buffer = new byte[1048];
int read = 0;
while ((read = res.Read(buffer, 0, buffer.Length)) > 0)
{
Console.Write(Encoding.ASCII.GetString(buffer, 0, read));
ret += Encoding.ASCII.GetString(buffer, 0, read);
}
return ret;
或者
private void Test()
{ ServicePointManager.ServerCertificateValidationCallback += new
RemoteCertificateValidationCallback(Certificate);
}
private static bool Certificate(object sender, X509Certificate certificate,
X509Chain chain, SslPolicyErrors policyErrors) {
return true;
}
检查此链接以获取更多信息http://blogs.msdn.com/b/dgorti/archive/2005/09/18/471003.aspx