試試這個
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;
}
檢查此鏈接而不是
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
更多信息http://blogs.msdn.com/b/dgorti/archive/2005/09/18/471003.aspx
您是否使用'ex.ToString()'顯示了整個異常?可能有一個'InnerException'試圖更詳細地告訴你問題是什麼。 –
對於示例代碼,提供代表性示例數據而不是隨機屬性好得多(例如'DownloadString(「https:// myserver/foo?bar = 222」)'而不是'DownloadString(NotGoingToShowValue)') –
檢查我的回答如果你仍然面臨問題...分享的網址,並告訴我們你需要激動...什麼是你提到的「博士」 – Aravind