473,324 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Persistemt https session?

Hi, I am trying to connect to an https server and download a file. The server
requires a client side certificate, which I have loaded successfully using
the X509Certificate class. I then add this certificate to the HttpWebRequest
class and connect to the server.

The problem arises because the initial request to the server gets a 302
redirect response. This response is OK, and is also recieved in IE7. The
second request in IE7 is not redirected, and I can download the file
successfully. However, if I try this from my C# client I get the redirect on
the first and second request. Is the SSL connection being renegotiated at
every request?

Code:
static HttpWebRequest GetHttpRequest()
{
X509Certificate cert = new X509Certificate(@"c:\cert.P12", "somePassword");
string url = "https://www.cdinternet.com/Reports/someTextFile.TXT";
Uri clearstream = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(clearstream);
request.ClientCertificates.Add(cert);
request.Proxy = GetProxy();
request.AllowAutoRedirect = false;
request.ProtocolVersion = HttpVersion.Version10;
request.KeepAlive = true;
HttpRequestCachePolicy noCachePolicy = new
HttpRequestCachePolicy(HttpRequestCacheLevel.NoCac heNoStore);
request.CachePolicy = noCachePolicy;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET
CLR 1.1.4322; .NET CLR 2.0.50727)";
request.PreAuthenticate = false;
request.Pipelined = true;
return request;
}

I am calling this method by:
request = GetHttpRequest();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
..... process stream.....
.... repeat the request...
request = GetHttpRequest();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
..... process stream.....

Any advice would be welcome. If I have left out any necessary detail please
let me know.

Thanks,
David.
Feb 19 '07 #1
2 5376
This is the reply I get from the server:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>302 Found</TITLE>
</HEAD><BODY>
<H1>Found</H1>
The document has moved <A HREF=" / " >here</A>.<P>
</BODY></HTML>

If I set the AllowAutoRedirect propert on the HttpWebRequest to true, the
app just hangs when doing the request.GetResponse().

As mentioned before I get this response every time the request is made. IE7
redirects the first time the page is requested, but gets the document on the
second request.

Thanks in advance!

"David Kirkland" wrote:
Hi, I am trying to connect to an https server and download a file. The server
requires a client side certificate, which I have loaded successfully using
the X509Certificate class. I then add this certificate to the HttpWebRequest
class and connect to the server.

The problem arises because the initial request to the server gets a 302
redirect response. This response is OK, and is also recieved in IE7. The
second request in IE7 is not redirected, and I can download the file
successfully. However, if I try this from my C# client I get the redirect on
the first and second request. Is the SSL connection being renegotiated at
every request?

Code:
static HttpWebRequest GetHttpRequest()
{
X509Certificate cert = new X509Certificate(@"c:\cert.P12", "somePassword");
string url = "https://www.cdinternet.com/Reports/someTextFile.TXT";
Uri clearstream = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(clearstream);
request.ClientCertificates.Add(cert);
request.Proxy = GetProxy();
request.AllowAutoRedirect = false;
request.ProtocolVersion = HttpVersion.Version10;
request.KeepAlive = true;
HttpRequestCachePolicy noCachePolicy = new
HttpRequestCachePolicy(HttpRequestCacheLevel.NoCac heNoStore);
request.CachePolicy = noCachePolicy;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET
CLR 1.1.4322; .NET CLR 2.0.50727)";
request.PreAuthenticate = false;
request.Pipelined = true;
return request;
}

I am calling this method by:
request = GetHttpRequest();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
.... process stream.....
... repeat the request...
request = GetHttpRequest();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
.... process stream.....

Any advice would be welcome. If I have left out any necessary detail please
let me know.

Thanks,
David.
Feb 19 '07 #2
Problem solved :-)
The server was sending back a cookie as part of the response. To fix the
problem all I had to do was set this cookie value on the second request
object. Voila!

Hope this is useful to someone in the future....

Many Thanks,
David.

"David Kirkland" wrote:
This is the reply I get from the server:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>302 Found</TITLE>
</HEAD><BODY>
<H1>Found</H1>
The document has moved <A HREF=" / " >here</A>.<P>
</BODY></HTML>

If I set the AllowAutoRedirect propert on the HttpWebRequest to true, the
app just hangs when doing the request.GetResponse().

As mentioned before I get this response every time the request is made. IE7
redirects the first time the page is requested, but gets the document on the
second request.

Thanks in advance!

"David Kirkland" wrote:
Hi, I am trying to connect to an https server and download a file. The server
requires a client side certificate, which I have loaded successfully using
the X509Certificate class. I then add this certificate to the HttpWebRequest
class and connect to the server.

The problem arises because the initial request to the server gets a 302
redirect response. This response is OK, and is also recieved in IE7. The
second request in IE7 is not redirected, and I can download the file
successfully. However, if I try this from my C# client I get the redirect on
the first and second request. Is the SSL connection being renegotiated at
every request?

Code:
static HttpWebRequest GetHttpRequest()
{
X509Certificate cert = new X509Certificate(@"c:\cert.P12", "somePassword");
string url = "https://www.cdinternet.com/Reports/someTextFile.TXT";
Uri clearstream = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(clearstream);
request.ClientCertificates.Add(cert);
request.Proxy = GetProxy();
request.AllowAutoRedirect = false;
request.ProtocolVersion = HttpVersion.Version10;
request.KeepAlive = true;
HttpRequestCachePolicy noCachePolicy = new
HttpRequestCachePolicy(HttpRequestCacheLevel.NoCac heNoStore);
request.CachePolicy = noCachePolicy;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET
CLR 1.1.4322; .NET CLR 2.0.50727)";
request.PreAuthenticate = false;
request.Pipelined = true;
return request;
}

I am calling this method by:
request = GetHttpRequest();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
.... process stream.....
... repeat the request...
request = GetHttpRequest();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
.... process stream.....

Any advice would be welcome. If I have left out any necessary detail please
let me know.

Thanks,
David.
Feb 19 '07 #3

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

Similar topics

1
by: Josip Krapac | last post by:
Hello, I've got this situation: Servlet accessed by https (ie. https://host.domain/SecureServlet) starts a session (HttpSession session = req.getSession(true)), sets some session attributes...
1
by: Kenneth Keeley | last post by:
Hi I wish to have a web site that has most of the pages as normal HTTP pages but has some areas that use HTTPS. I want to have it that if a user selects a link to a HTTPS page that they go there...
6
by: Astra | last post by:
Hi All I've noticed on quite a few ASP sites that when they have a 'MyAccount' section they transfer the site to https and then when you have logged into your account successfully and gone back...
12
by: Grunff | last post by:
I'm experiencing an interesting problem with carrying a php session over from http to https. Much googling later, I'm still stuck. The application is an online shop, where some user data is...
3
by: mike parr | last post by:
I have written a couple of HTTPS websites using notepad, and now I'm trying to write one in VS.NET but I'm having a few problems. I need a default file in the root folder which redirects to a...
0
by: vickeybird | last post by:
Hi, My current application requires me to use HTTPS and Cookieless Sessions. Ive just implemented HHTP Handler to redirect all http request to https as described by Matt Sollars at...
0
by: NoaGross | last post by:
Hi, I'm relly new in java and I have a problem. I'm using java applet. When using http all ok, but when trying to use https i get: Java Plug-in 1.5.0_10 Using JRE version 1.5.0_10 Java...
2
by: =?Utf-8?B?YW5vb3A=?= | last post by:
Hello, I am developing a Simple ASP Application with a Login page. I want to know how session ID can be generated after User has authenticated instead of generation along with the Login page...
4
by: totalstranger | last post by:
My Bluehost site is setup with a dedicated IP address, Rapid SSL certificate, PHP 5 and FastCGI is set on. When switching between HTTP and HTTPS I was under the impression the Session Data was...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.