How to read XML from the internet using a Web Proxy?

Posted by Mark Allison on Stack Overflow See other posts from Stack Overflow or by Mark Allison
Published on 2011-01-11T13:46:37Z Indexed on 2011/01/11 13:53 UTC
Read the original article Hit count: 477

Filed under:
|

This is a follow-up to this question: How to load XML into a DataTable?

I want to read an XML file on the internet into a DataTable. The XML file is here: http://rates.fxcm.com/RatesXML

If I do:

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;
}

It works fine. I'm struggling with how to use the default proxy set in Internet Explorer. I don't want to hard-code the proxy. I also want the code to work if no proxy is specified in Internet Explorer.

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml