473,395 Members | 1,702 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,395 software developers and data experts.

Get session cookies from webrequest and pass then to new request

I am making a console app that requests pages from our site one after
another. Each request starts a new session, What I want to do is make all
requests in the same session.

How can I do this.

I was hoping to be able to get the session back from first request and then
set them on each further request.

Any ideas?

Jul 3 '08 #1
3 8771
ThatsIT.net.au used his keyboard to write :
I am making a console app that requests pages from our site one after
another. Each request starts a new session, What I want to do is make all
requests in the same session.

How can I do this.

I was hoping to be able to get the session back from first request and then
set them on each further request.

Any ideas?
There is a CookieContainer specifically for this scenario:
create one and add it to every request you issue.

Hans Kesting
Jul 3 '08 #2
ThatsIT.net.au wrote:
I am making a console app that requests pages from our site one after
another. Each request starts a new session, What I want to do is make
all requests in the same session.

How can I do this.

I was hoping to be able to get the session back from first request and
then set them on each further request.
Example of using CookieContainer:

using System;
using System.IO;
using System.Net;

namespace E
{
public class MainClass
{
public static string GetContent(string url, CookieContainer
session)
{
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
wr.CookieContainer = session;
string html = (new
StreamReader(wr.GetResponse().GetResponseStream()) ).ReadToEnd();
return html;
}
public static void Main(string[] args)
{
CookieContainer session = new CookieContainer();
string login =
GetContent("http://localhost:8080/logintest/login.jsp?username=arne&password=hemmeligt",
session);
Console.WriteLine(login);
string other =
GetContent("http://localhost:8080/logintest/other.jsp", session);
Console.WriteLine(other);
}
}
}

Arne
Jul 3 '08 #3
Sorry I did not get back earlier,

thanks very much ill try it

"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:48***********************@news.sunsite.dk...
ThatsIT.net.au wrote:
>I am making a console app that requests pages from our site one after
another. Each request starts a new session, What I want to do is make all
requests in the same session.

How can I do this.

I was hoping to be able to get the session back from first request and
then set them on each further request.

Example of using CookieContainer:

using System;
using System.IO;
using System.Net;

namespace E
{
public class MainClass
{
public static string GetContent(string url, CookieContainer
session)
{
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
wr.CookieContainer = session;
string html = (new
StreamReader(wr.GetResponse().GetResponseStream()) ).ReadToEnd();
return html;
}
public static void Main(string[] args)
{
CookieContainer session = new CookieContainer();
string login =
GetContent("http://localhost:8080/logintest/login.jsp?username=arne&password=hemmeligt",
session);
Console.WriteLine(login);
string other =
GetContent("http://localhost:8080/logintest/other.jsp", session);
Console.WriteLine(other);
}
}
}

Arne
Jul 13 '08 #4

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

Similar topics

27
by: mrbog | last post by:
Tell me if my assertion is wrong here: The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate...
1
by: Craig | last post by:
I wrote a generic page to do HttpWebRequest operations based on 3 querystring parameters for the uri, username, and password for basic authentication pages. The page is designed to help with...
3
by: Paul | last post by:
Hello, First I want to refer to the problem "WebRequest : execute a button" of a few days ago. The way I solved it, I loose my session, and as a consequence my session variables. I don't want...
3
by: Karsten Grombach | last post by:
Hi, I'm trying the following: - Imitate a Logon using a Post with HttpWebRequest on remote Webserver (asp 3.0 page using https) - On success redirect to the page (encapsuled in an iframe)...
3
by: Amil | last post by:
Please don't repond to this if you are guessing or just don't know the answer. I'm trying to login to a backend system running Java/Tomcat. I create a HttpWebRequest with the login data and do...
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
4
by: mike.biang | last post by:
I have an ASP page that is using an XMLHTTP object to request various pages from my server. I keep a single session throughout the XMLHTTP requests by bassing the ASPSESSIONID cookie through the...
1
by: ALA | last post by:
Hi, does anybody know if it is possible to pass the SessionID with a web request by using a cookie so that the invoked page in the same domain can access the session objects of the current user?...
3
by: ThatsIT.net.au | last post by:
I am making a console app that requests pages from our site one after another. Each request starts a new session, What I want to do is make all requests in the same session. How can I do this. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...

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.