473,587 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTTP Network Programming Issue

I'm trying to log in to a secured web site automatically using c#. To
do this I have go through a proxy server, and use SSL, and log in to
the secure site with another user name and password (different from the
proxy user name and password).

Now, I can get through the proxy by setting the correct credentials on
the WebProxy. I can get through SSL by setting up a dummy certificate
policy class that always returns true. If I go to a regular web site
like http:\\www.google.com it works. If I go to SSL site
(https:\\siteus ingssl.com\) then it works. The problem occurs when
trying to access the site that requires all three methods. The error
returned is 401: Unauthorized. I think the site may use cookies, but I
can't check the cookies returned in the response object because when I
do the request.GetResp onse() it always throws an exception and doesn't
return a valid response object.

If you've read this much, then you deserve to see the code of my most
recent attempt:

//Set Up The Proxy Server
WebProxy proxy = new WebProxy("http://my.proxy.com:31 28/", true);
CredentialCache proxyCache = new CredentialCache () ;
proxyCache.Add( new Uri("http://my.proxy.com:31 28/"), "Basic", new
NetworkCredenti al("user", "pw")) ;
proxyCache.Add( new Uri("https://the.secured.com/"), "Basic", new
NetworkCredenti al("user", "pw")) ;

proxy.Credentia ls = proxyCache ;
request = WebRequest.Crea te("https://the.secured.com ") ;
request.Proxy = proxy;

//Set Up SSL
ServicePointMan ager.Certificat ePolicy = new CertPolicy();

// Send the 'HttpWebRequest ' and wait for response.
HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();

Any help will be much appreciated.

Thanks,

Brent

Nov 17 '05 #1
3 2281
Hi,

Look at this page:
http://weblogs.asp.net/wim/archive/2...02/106281.aspx

Hope it helps...
o.f

"bd-chan" <br*********@ya hoo.com> wrote in news:1116520425 .801933.64120
@z14g2000cwz.go oglegroups.com:
I'm trying to log in to a secured web site automatically using c#. To
do this I have go through a proxy server, and use SSL, and log in to
the secure site with another user name and password (different from the
proxy user name and password).

Now, I can get through the proxy by setting the correct credentials on
the WebProxy. I can get through SSL by setting up a dummy certificate
policy class that always returns true. If I go to a regular web site
like http:\\www.google.com it works. If I go to SSL site
(https:\\siteus ingssl.com\) then it works. The problem occurs when
trying to access the site that requires all three methods. The error
returned is 401: Unauthorized. I think the site may use cookies, but I
can't check the cookies returned in the response object because when I
do the request.GetResp onse() it always throws an exception and doesn't
return a valid response object.

If you've read this much, then you deserve to see the code of my most
recent attempt:

//Set Up The Proxy Server
WebProxy proxy = new WebProxy("http://my.proxy.com:31 28/", true);
CredentialCache proxyCache = new CredentialCache () ;
proxyCache.Add( new Uri("http://my.proxy.com:31 28/"), "Basic", new
NetworkCredenti al("user", "pw")) ;
proxyCache.Add( new Uri("https://the.secured.com/"), "Basic", new
NetworkCredenti al("user", "pw")) ;

proxy.Credentia ls = proxyCache ;
request = WebRequest.Crea te("https://the.secured.com ") ;
request.Proxy = proxy;

//Set Up SSL
ServicePointMan ager.Certificat ePolicy = new CertPolicy();

// Send the 'HttpWebRequest ' and wait for response.
HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();

Any help will be much appreciated.

Thanks,

Brent


Nov 17 '05 #2
If I unerstand you correctly, you are saying that you cannot get to a site
which requires Cookie, Authentication and SSL at the same time, while going
through a proxy that also requires authentication.

If so, looking at your code below, I dont see you adding credential to the
HttpWebRequest object. You should set credentials on the HttpWebRequest as
well, otherwise your credentials wont be sent, and hence the request will
get denied with a 401.

--
feroze

-----------------
This posting is provided as-is. It offers no warranties and assigns no
rights.

See http://weblogs.asp.net/feroze_daud for System.Net related posts.
----------------

"bd-chan" <br*********@ya hoo.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
I'm trying to log in to a secured web site automatically using c#. To
do this I have go through a proxy server, and use SSL, and log in to
the secure site with another user name and password (different from the
proxy user name and password).

Now, I can get through the proxy by setting the correct credentials on
the WebProxy. I can get through SSL by setting up a dummy certificate
policy class that always returns true. If I go to a regular web site
like http:\\www.google.com it works. If I go to SSL site
(https:\\siteus ingssl.com\) then it works. The problem occurs when
trying to access the site that requires all three methods. The error
returned is 401: Unauthorized. I think the site may use cookies, but I
can't check the cookies returned in the response object because when I
do the request.GetResp onse() it always throws an exception and doesn't
return a valid response object.

If you've read this much, then you deserve to see the code of my most
recent attempt:

//Set Up The Proxy Server
WebProxy proxy = new WebProxy("http://my.proxy.com:31 28/", true);
CredentialCache proxyCache = new CredentialCache () ;
proxyCache.Add( new Uri("http://my.proxy.com:31 28/"), "Basic", new
NetworkCredenti al("user", "pw")) ;
proxyCache.Add( new Uri("https://the.secured.com/"), "Basic", new
NetworkCredenti al("user", "pw")) ;

proxy.Credentia ls = proxyCache ;
request = WebRequest.Crea te("https://the.secured.com ") ;
request.Proxy = proxy;

//Set Up SSL
ServicePointMan ager.Certificat ePolicy = new CertPolicy();

// Send the 'HttpWebRequest ' and wait for response.
HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();

Any help will be much appreciated.

Thanks,

Brent

Nov 17 '05 #3
If I unerstand you correctly, you are saying that you cannot get to a site
which requires Cookie, Authentication and SSL at the same time, while going
through a proxy that also requires authentication.

If so, looking at your code below, I dont see you adding credential to the
HttpWebRequest object. You should set credentials on the HttpWebRequest as
well, otherwise your credentials wont be sent, and hence the request will
get denied with a 401.

--
feroze

-----------------
This posting is provided as-is. It offers no warranties and assigns no
rights.

See http://weblogs.asp.net/feroze_daud for System.Net related posts.
----------------

"bd-chan" <br*********@ya hoo.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
I'm trying to log in to a secured web site automatically using c#. To
do this I have go through a proxy server, and use SSL, and log in to
the secure site with another user name and password (different from the
proxy user name and password).

Now, I can get through the proxy by setting the correct credentials on
the WebProxy. I can get through SSL by setting up a dummy certificate
policy class that always returns true. If I go to a regular web site
like http:\\www.google.com it works. If I go to SSL site
(https:\\siteus ingssl.com\) then it works. The problem occurs when
trying to access the site that requires all three methods. The error
returned is 401: Unauthorized. I think the site may use cookies, but I
can't check the cookies returned in the response object because when I
do the request.GetResp onse() it always throws an exception and doesn't
return a valid response object.

If you've read this much, then you deserve to see the code of my most
recent attempt:

//Set Up The Proxy Server
WebProxy proxy = new WebProxy("http://my.proxy.com:31 28/", true);
CredentialCache proxyCache = new CredentialCache () ;
proxyCache.Add( new Uri("http://my.proxy.com:31 28/"), "Basic", new
NetworkCredenti al("user", "pw")) ;
proxyCache.Add( new Uri("https://the.secured.com/"), "Basic", new
NetworkCredenti al("user", "pw")) ;

proxy.Credentia ls = proxyCache ;
request = WebRequest.Crea te("https://the.secured.com ") ;
request.Proxy = proxy;

//Set Up SSL
ServicePointMan ager.Certificat ePolicy = new CertPolicy();

// Send the 'HttpWebRequest ' and wait for response.
HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();

Any help will be much appreciated.

Thanks,

Brent

Nov 17 '05 #4

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

Similar topics

8
50557
by: Alex Ang | last post by:
I have written the following VBScript program. It is stored into a file "map_drive.vbs". It successfully mapped to a network drive \\server1\data. Dim WshNetwork Set WshNetwork = WScript.CreateObject("WScript.Network") sPwd = inputbox("Enter password") WshNetwork.MapNetworkDrive "J:", "\\server1\data", false, "xyz_net\John", sPwd...
3
14857
by: Jay | last post by:
Hi, I implemeneted an FTP client and server long time back using Java. I found sockets porgramming in java quite useful and easy to handle. I now wanted to implement a similar program using C++. My questions are 1. How good a language is C++ for network programming? 2. what are good onine resources to learn C++ network programming? 3. How...
4
1706
by: Wayne M J | last post by:
I have "Professional .Net Network Programming" and "Network Programming for MS Windows 2nd Ed", but I find both of these to be lacking in what I am looking for. Has there been any books printed on serious network programming for C# that deals with the IP Helper routines?
5
2166
by: Terry | last post by:
Could someone please suggest me a good book to learn network programming. I have been programming in C#/VB.NET/VB 6.0 and have also used a bit of C++ (not MFC/ATL/COM) I am a total novice when it comes to networks and I don't even know the basics. I need a book which teaches me everything I need to get started with programming in...
4
2471
by: Bob Badger | last post by:
Hi, Simple question (although I guess with a complicated answer). Is HTTP an async protocol? For instance, if I send a message to a c# webservice via http what is the protocol actually doing? Thanks in advance Steffan
10
3223
by: rup | last post by:
Hello, This is my first application on socket programming in vc++. I am facing problem that how to make connection to server, & make GET/POST request by HTTP. Please help me. Its urgent.... Thanks
2
4958
by: =?Utf-8?B?c29feV9ub3Q2OQ==?= | last post by:
I got the Vista & Xp machine on a wired network and I can access the Xp machine no problem. The trouble is Xp is looking for a Username & password to access the Vista machine. In the network and sharing center, If I select public folder sharing or Printer sharing, it says that a password is required. Where exactly does this password come...
2
4653
by: =?Utf-8?B?RGFycmVs?= | last post by:
I don't know if this is an ASP.NET issue, an IIS issue, or a user browser issue, but on one of our web applications we have been getting an increasing amount of 400 'Bad Request' errors. The following is what we know about the issue mostly from looking at LiveStats and the IIS log: - It is Intermittent. Most of the time it behaves correctly...
2
1938
by: baker_tony | last post by:
Hi, is there any way of getting details (such as last modified/ created date/time) of a file located on the web? E.g I'd like to know when the file "http://www.myWebSite.com/ update.txt" was last created/modified. I'm *guessing* I can use CHttpResponse to get some "Last-Modified" value, but I've found it very difficult to get come...
9
2365
by: Mex | last post by:
Hi, I'm looking for a good book for beginners about Network Programming. Besides Stevens' book, I would like something specific for C++ language. Any suggestions? Thanks in advantage, Massimo
0
7852
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...
0
8216
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. ...
0
8349
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...
1
7974
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...
0
8221
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...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
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...

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.