这是这个问题的后续:How to load XML into a DataTable?
我想将 Internet 上的 XML 文件读入 DataTable 中。 XML 文件在这里:http://rates.fxcm.com/RatesXML
如果我这样做:
public DataTable GetCurrentFxPrices(string url)
{
WebProxy wp = new WebProxy("http://mywebproxy:8080", true);
wp.Credentials = CredentialCache.DefaultCredentials;
WebClient wc = new WebClient();
wc.Proxy = wp;
MemoryStream ms = new MemoryStream(wc.DownloadData(url));
DataSet ds = new DataSet("fxPrices");
ds.ReadXml(ms);
DataTable dt = ds.Tables["Rate"];
return dt;
}
它工作正常。我正在为如何使用 Internet Explorer 中设置的默认代理而苦恼。我不想硬编码代理。如果没有在 Internet Explorer 中指定代理,我也希望代码能够工作。
最佳答案
您可以使用 Console.WriteLine(System.Net.WebProxy.GetDefaultProxy().Address.AbsoluteUri); ...
关于c# - 如何使用 Web 代理从 Internet 读取 XML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4658253/