473,804 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Net.WebC lient with Proxy and Credentials

I try getting response from web site through proxy in my domain:

WebClient wc = new WebClient();
WebProxy wProxy = new WebProxy();

CredentialCache cc = new CredentialCache ();
NetworkCredenti al nc = new NetworkCredenti al("myUsername" , "myPassword ",
"myDomain") ;
cc.Add("myProxy .domain.local", 8080, "Basic", nc);
// should this be: cc.Add("http://myProxy.domain. local", 8080, "Basic", nc);
?? got same error

wProxy.Credenti als = cc;
wc.Proxy = wProxy;

string html = wc.DownloadStri ng(new Uri("http://www.google.com/"));

MessageBox.Show (this, html);
I get error:
Message : Unable to connect to the remote server
InnerException : A connection attempt failed because the connected party did
not properly respond after a period of time, or established connection
failed because connected host has failed to respond
Is there a way to test just getting to proxy server and/or passing through
it?

Thanx.
Jun 30 '06 #1
2 40625
This is one way that I do it:

WebProxy p = null;
string proxyAddressAnd Port =
ConfigurationMa nager.AppSettin gs["proxy"];
string proxyUserName =
ConfigurationMa nager.AppSettin gs["proxyUserN ame"];
string proxyPassword =
ConfigurationMa nager.AppSettin gs["proxyPassw ord"];
ICredentials cred;
cred = new NetworkCredenti al(proxyUserNam e, proxyPassword);
p = new WebProxy(proxyA ddressAndPort, true, null, cred);
WebRequest.Defa ultWebProxy = p;

-That's for ASP.NET 2.0 , the last line for ASP.NET 1.1 would be like yours.

The IP address of the actual proxy server and port would look like:

10.10.128.3:808 0
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"TheMaxx" wrote:
I try getting response from web site through proxy in my domain:

WebClient wc = new WebClient();
WebProxy wProxy = new WebProxy();

CredentialCache cc = new CredentialCache ();
NetworkCredenti al nc = new NetworkCredenti al("myUsername" , "myPassword ",
"myDomain") ;
cc.Add("myProxy .domain.local", 8080, "Basic", nc);
// should this be: cc.Add("http://myProxy.domain. local", 8080, "Basic", nc);
?? got same error

wProxy.Credenti als = cc;
wc.Proxy = wProxy;

string html = wc.DownloadStri ng(new Uri("http://www.google.com/"));

MessageBox.Show (this, html);
I get error:
Message : Unable to connect to the remote server
InnerException : A connection attempt failed because the connected party did
not properly respond after a period of time, or established connection
failed because connected host has failed to respond
Is there a way to test just getting to proxy server and/or passing through
it?

Thanx.

Jun 30 '06 #2
Thanx!
this worked for me!

now i'll try to find out what's wrong with my code.
:)
"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com > wrote in message
news:40******** *************** ***********@mic rosoft.com...
This is one way that I do it:

WebProxy p = null;
string proxyAddressAnd Port =
ConfigurationMa nager.AppSettin gs["proxy"];
string proxyUserName =
ConfigurationMa nager.AppSettin gs["proxyUserN ame"];
string proxyPassword =
ConfigurationMa nager.AppSettin gs["proxyPassw ord"];
ICredentials cred;
cred = new NetworkCredenti al(proxyUserNam e, proxyPassword);
p = new WebProxy(proxyA ddressAndPort, true, null, cred);
WebRequest.Defa ultWebProxy = p;

-That's for ASP.NET 2.0 , the last line for ASP.NET 1.1 would be like
yours.

The IP address of the actual proxy server and port would look like:

10.10.128.3:808 0
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"TheMaxx" wrote:
I try getting response from web site through proxy in my domain:

WebClient wc = new WebClient();
WebProxy wProxy = new WebProxy();

CredentialCache cc = new CredentialCache ();
NetworkCredenti al nc = new NetworkCredenti al("myUsername" ,
"myPassword ",
"myDomain") ;
cc.Add("myProxy .domain.local", 8080, "Basic", nc);
// should this be: cc.Add("http://myProxy.domain. local", 8080, "Basic",
nc);
?? got same error

wProxy.Credenti als = cc;
wc.Proxy = wProxy;

string html = wc.DownloadStri ng(new Uri("http://www.google.com/"));

MessageBox.Show (this, html);
I get error:
Message : Unable to connect to the remote server
InnerException : A connection attempt failed because the connected party
did
not properly respond after a period of time, or established connection
failed because connected host has failed to respond
Is there a way to test just getting to proxy server and/or passing
through
it?

Thanx.

Jun 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2033
by: Chamander2kool | last post by:
I use Godday.com for hosting. What I'm trying to do is create a web proxy. This is the code I have currently: <%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %> <%@ Page Language="VB" Debug="true" %>
2
4183
by: cindy.fisher | last post by:
I am using DownloadFile() on a C# web app to download a file to a client. When I set the WebClient credentials to the DefaultCredentials, I get a 401 Unauthorized exception. WebClient myWC = new WebClient(); myWC.Credentials = CredentialCache.DefaultCredentials; myWC.DownloadFile(myRemoteUri, myFile); However, when I set the credentials using a username and password it works.
4
30080
by: Morten Snedker | last post by:
I'm trying to download a file. I've tried both using webclient and the httpWebRequest. Either way it returns a "407 proxy authentication required". The program is to be run externally, so basically I don't know the users login-name, password or domain. So that makes setting the proxy in code irrelevant, doesn't it? When searching the web it appears to be a common problem. But I haven't found my solution and still can't get it to...
2
5979
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an application to download images using System.NET classes (webclient, webrequest) asynchronously behind proxy server. The reading method works like this: System.Net.WebClient client=new System.Net.WebClient();
0
3105
by: WSchaub | last post by:
Has anyone got any referece documentation on how to set the proxy credentials and set proxy server details in WCF proxies? Basically I want to do the following two scenarios we have done in pre-WCF environments: //Set proxy credentials ServiceB.ServiceB remoteService = new ServiceB.ServiceB();
1
12507
by: Mike | last post by:
I am using PowerShell to download an XML file into a string using the DownloadString(URI) method of System.Net.WebClient object. Sample commands below: $Result = $Null; $WebClient = new-object System.Net.WebClient; $WebClient.Encoding = ::Default; $WebClient.Proxy = ::DefaultWebProxy; $WebClient.Proxy.Credentials = ::DefaultCredentials;
1
4006
by: moo | last post by:
Is there a simple way to get my logon credentials to make my web request work through our proxy server? I tried CredentialCache.DefaultCredentials, but I get nothing back. I can get it to work if I just create a new NetworkCredential object specifying user, password and domain. But, I would rather get that info automatically if possible, rather than presenting a winform for them to type it in. Lastly, why do both the request object and...
1
2597
by: George | last post by:
My desktop application (C# 2.0) works just fine and makes tons of requests via WebRequest and WebClient objects. However, users that are behind Proxy servers are not able to use the app. I'm sure my head is not right on this issue and i need to seek advice. First, I dont really understand why I (the programmer) have to worry about these details - shouldnt this be somewhere below me on the ISO stack? But that sounds like complaining,...
0
2858
by: malkin | last post by:
Hi all, I have an external application that calls WebClient to download a file from our server. It runs fine without any proxy server involved. However, once there is a proxy server layer, it throws a 407 proxy authentication required error. My question is that since I do not know whether the users are going to download a file thru a proxy, is there a way in C# to specify a general way of coding to handle proxy and non-proxy users? ...
0
1385
by: rajib123 | last post by:
I am trying to write a windows utility that downloads some files from an ftp site to a local directory and then uploads those files to another ftp site. The files that I need to download are posted on the ftp site everyday. The file name contains the datetime stamp, so the filename changes everyday. Files are named as such: abc.com.ftc1.062210083741 I am using a ftpwebrequest method to get a listing of all the files on the ftp directory. Then...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10350
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10351
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.