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

httpwebrequests, cookies and sessionID

Hi,

I've been using httpwebrequest / xmlserverhttp to log into a website
via POST. I've received all the response headers back, some of which
contain the "set-cookie" headers.

When performing any other action on the website I need to submit the
JSESSION id and BSESSIONID as part of my POSTS.

I was just wondering where these session ids originate, from the server
or client side as I cannot see these in the response headers. If its
from the server how do I capture this? If it is client side, how does
one generate them? I assume if it is client side then they must be
being sent with my original log-in POST?

Thank you for any help,

Mike

Jan 27 '06 #1
6 3476
The Session ID is in a cookie that is sent with the Response. It can be a
bit tricky to get them out. Here's some code from a class I wrote, which
should work for you:

if (Response.Cookies != null && Response.Cookies.Count > 0)
Cookies = Response.Cookies;
else if (Response.Headers["Set-Cookie"] != null)
{
string[] cookie = Text.Split(Response.Headers["Set-Cookie"], ";");
string[] av = Text.Split(cookie[0], "=");
Cookie c = new Cookie(av[0], av[1]);
c.Domain = Response.ResponseUri.Host;
Cookies.Add(c);
}

Cookies is a field that is of the type System.Net.CookieCollection.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Mike" <my***@pearcey2001.freeserve.co.uk> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi,

I've been using httpwebrequest / xmlserverhttp to log into a website
via POST. I've received all the response headers back, some of which
contain the "set-cookie" headers.

When performing any other action on the website I need to submit the
JSESSION id and BSESSIONID as part of my POSTS.

I was just wondering where these session ids originate, from the server
or client side as I cannot see these in the response headers. If its
from the server how do I capture this? If it is client side, how does
one generate them? I assume if it is client side then they must be
being sent with my original log-in POST?

Thank you for any help,

Mike

Jan 27 '06 #2
Thank you very much for responding, I will give the code a try.

Kind regards,

Jan 27 '06 #3

Sorry this is still causing me a problem. In vb.net pseudo:

1 xmlhttp1 = CreateObject("MSXML2.ServerXMLHTTP.3.0")
2 xmlhttp1.Open("POST", "url", ....)
3 xmlhttp1.setRequestHeader("Accept", ".........."
4 xmlhttp1.setRequestHeader("Referer",
"http://www......................")
5 xmlhttp1.setRequestHeader("Accept-Language", "en-gb")
6 xmlhttp1.setRequestHeader("Content-Type", "
application/x-www-form-urlencoded")
7 xmlhttp1.setRequestHeader("Accept-Encoding", " gzip, deflate")
8 xmlhttp1.setRequestHeader("User-Agent", "Mozilla/4.0
(compatible.............")
9 xmlhttp1.setRequestHeader("Host", " www................")
10 xmlhttp1.setRequestHeader("Content-Length", ".......")
11 xmlhttp1.setRequestHeader("Proxy-Connection", "Keep-Alive")
12 xmlhttp1.setRequestHeader("Cache-Control", "cache")

13 xmlhttp1.send("username=.........&password=....... .&LoginB=......")

14 responsestring = xmlhttp1.getallResponseHeaders.ToString

If I look at the response I have received the following:

Date: Fri, 27 Jan 2006 20:42:39 GMT
Server: ................
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: userhistory=...................;Path=/;Expires=Sat,
27-Jan-07 20:42:39 GMT
Content-Type: text/html; charset=UTF-8
Cache-Control: no-store
Pragma: no-cache
Transfer-Encoding: chunked
Set-Cookie: NSC_cfufy=0a0a0aba1f90;expires=Sat,28-Jan-06 08:42:39
GMT;path=/

In your code you split out the parts of the "set-cookie" headers,
separated by ";" but I can't see anything about sessions in the
responses.

have I missed the point or is this information hidden somehow?

Many thanks,

Mike

Jan 27 '06 #4
I've realised where I was going wrong; if I do a "GET" to the host URL
first I get all the sessionID info back in the headers.

Then I can do the subsequent log-in and further action using this same
Id.

Kind regards,

Mike

Jan 28 '06 #5
Ok this is driving me crazy.
If I log onto the website normally, watch the traffic, extract the
session id, use it in my program it works fine.

If I direct my winform app to make a POST to the main site I get no
session id back.
If I make a GET to the main part of the website I get a session id
returned. Now if I use this extracted session id to make the log-in
POST it does not work.
The last part of the url for my GET and POST is different, but I
assumed that if I maintain the MSXML2.ServerXMLHTTP.3.0 object between
the GET and POST there is no reason the sessionid would change??

Please can anyone offer a suggestion?

Thanks

Jan 28 '06 #6
used httpwebrequest rather than ServerXMLHTTP in the end - much easier.
Session Ids were sent back with the first POST made.

Jan 28 '06 #7

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

Similar topics

4
by: Cezar | last post by:
Hi, does anyone know how to create a login system with PHP that does not use cookies? I am finding that more and more users seem to be setting their privacy settings to high, this not accepting...
1
by: Angus SC2 | last post by:
Hi I am trying to set up cross domain cookies on a server I have running that currently has 2 domains running on it (on different IPs). Basically I have a forums site (using UBB threads) and I...
0
by: Maverick | last post by:
Hello all, I read some good reviews about jakarta HTTPClient about its session and cookies management system and fancied giving it a try as a learning exercise but somehow I don't seem to be able...
0
by: Pat Allan | last post by:
I've spent half a day on this with no success, so I'm hoping someone can point out what I'm doing wrong. I have an ASP.NET Server-side component that I've created, and as part of its Render...
2
by: Chris | last post by:
I have an aspx page that is called from an asp page. When I read the httpcookie in asp.net I get the dashes and slashes converted to a "%3" and such. Is there was way to convert it back to normal...
6
by: DJones | last post by:
I'm using the following code in my .Net application (.Net v1.1, Windows 2000) to write Session Cookies. HttpContext.Current.Response.Cookies("cookieSession")("SessionID") = strSessionID ...
3
by: beaker | last post by:
Hello, I'm trying to write an app which will periodically log in to a game website so I can check for changes to some of my player info. The code I've come up with so far is below, and, as you...
3
by: Victor | last post by:
I was thinking about an easy to determine if cookies are set or not in ASP. I began thinking about how the Session ID is dependent upon a cookie - right? Well, I disabled cookies in Firefox and...
2
by: StanB | last post by:
I came across this weird problem: 1. Session state stops working after the app is deployed to another server because IE does not accept cookies. 2. It works if cookieless="true" in the...
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: 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
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.