473,385 Members | 1,780 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,385 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 3157
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.