-2

This is my code. What am i trying to do is connect to webservice and download a file to a specific location.

Code throws an exception. Looks like i should retun some value to service before i download a file (not sure tho).

WebClient webClient = new WebClient();
NetworkCredential netCred=new NetworkCredential();
netCred.UserName="user";
netCred.Password="pass";
netCred.Domain="domain";
webClient.Credentials = netCred;
WebProxy wp = new WebProxy();
wp.Credentials = netCred;
wp.Address = new Uri(@"http://okolje.arso.gov.si/service/prevozniki.zip");
webClient.Proxy = wp;
webClient.DownloadFile("http://okolje.arso.gov.si/service/prevozniki.zip", @"C:\arso\prevozniki.zip");
svick
  • 236,525
  • 50
  • 385
  • 514
Tagyoureit
  • 359
  • 1
  • 5
  • 18
  • 3
    I'm not sure what your question is - can you clarify? What is the exception thrown? What do you want to do when you encounter the exception? – DGibbs Oct 08 '13 at 09:37
  • 2
    You're not setting the proxy address correctly: [`WebProxy.Address`](http://msdn.microsoft.com/en-us/library/system.net.webproxy.address.aspx): _"Gets or sets the address of the proxy server"_. – CodeCaster Oct 08 '13 at 09:41
  • i dont see the proxy address? http://stackoverflow.com/a/10779198/2027232 – string.Empty Oct 08 '13 at 09:41
  • thank you. My obvious mistake. Works now! – Tagyoureit Oct 08 '13 at 10:57

1 Answers1

0

you need to say what port your proxy is e.g.

webClient.Proxy = new WebProxy("127.0.0.1:8118");

you also have to actually set up this proxy, webclient.proxy just uses it, it doesn't create it

I'm not entirely sure what the rest of your code is doing, but I don't think you need the

wp.Address = new Uri(@"http://okolje.arso.gov.si/service/prevozniki.zip"); 
puser
  • 477
  • 4
  • 16