473,320 Members | 1,876 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,320 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 2549
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: Scott Wickham | last post by:
I'm having a problem saving session information on one form and retrieving it on a subsequent form...for only one out of a number of users. Actually, I'm not absolutely certain it's a session...
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
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.