Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMLDocument.Load(url) through a proxy

Tags:

c#

xml

proxy

I have a bit of code that basically reads an XML document using the XMLDocument.Load(uri) method which works fine, but doesn't work so well if the call is made through a proxy.

I was wondering if anyone knew of a way to make this call (or achieve the same effect) through a proxy?

like image 315
lomaxx Avatar asked Sep 24 '08 01:09

lomaxx


1 Answers

This is the code that I ended up using:

WebProxy wp = new WebProxy(Settings.Default.ProxyAddress);
wp.Credentials = new NetworkCredential(Settings.Default.ProxyUsername, Settings.Default.ProxyPassword);
WebClient wc = new WebClient();
wc.Proxy = wp;

MemoryStream ms = new MemoryStream(wc.DownloadData(url));
XmlTextReader rdr = new XmlTextReader(ms);
return XDocument.Load(rdr); 
like image 67
lomaxx Avatar answered Oct 05 '22 21:10

lomaxx