reciving cookie.how?

Byak@

Active Member
Licensed User
i aftorizizing in site
B4X:
Response.New1
Request.New1(url)
request.ContentType="application/x-www-form-urlencoded"
Request.Method = "Post"
FileOpen(c1,AppPath&"\sendcode2.txt",crandom)
strread.New1(c1,true)
request.ContentLength=strread.Length
Writer.New1(Request.GetStream,true)
Dim Buffer(4096) As byte
Reader.New1(c1,true)
count = Reader.ReadBytes(buffer(),4096)
Do While count > 0
Writer.WriteBytes2(buffer(),0,count)
count = Reader.ReadBytes(buffer(),4096)
Loop
FileClose(c1)
this site work with cookie/how can i recivi it before aftorizing?
 

bish0p

Member
Licensed User
Longtime User
Here is some sample code I use to get and set cookies with a website geocaching.com

B4X:
wwwreq.New1("http://www.geocaching.com/login/default.aspx")
wwwres.Value = wwwreq.GetResponse

regex.New1("ASP.NET_SessionId=.[a-zA-Z0-9;]+")
match.Value=regex.Match(wwwres.Headers)
GC_Session_ID=match.String

This gets there first session ID cookie before I am logged on

B4X:
wwwreq.AddHeader("Cookie",GC_Session_ID)   
wwwreq.New1("http://www.geocaching.com/login/default.aspx")

This sends the cookie back during hte login POST form

B4X:
regex.New1("ASP.NET_SessionId=.[a-zA-Z0-9;]+")
match.Value=regex.Match(wwwres.Headers)
GC_Session_ID=match.String
regex.New1("userid=.[a-zA-Z0-9\-;]+")
match.Value=regex.Match(wwwres.Headers)
GC_User_id=match.String

And this grabs the two cookies I need now that I am logged in. that continue to be sent back to the site. so you can dump them to a file or however you plan to keep them until they expire.
 

Byak@

Active Member
Licensed User
oh,thanks.but what is the regex?
 

bish0p

Member
Licensed User
Longtime User
oh,thanks.but what is the regex?

Regular expressions, commonly known as "RegEx" are a set of key combinations that are meant to allow people to have a large variety of control over what they are searching for.

Basically is allows you to search and match patterns in text If you add regex.dll to your project you can use the pattern matching power of regex to find many things..

this example

B4X:
regex.New1("ASP.NET_SessionId=.[a-zA-Z0-9;]+")

Means search for "ASP.NET_SessionId=" then any combination of letters the a-zA-Z or numbers 0-9 and the ";" <- which of course is at the end of each cookie. I use this one as the sessionid is of the format ASP.NET_SessionId=5kjh54jk5h434kj5h3k;

While this search

B4X:
regex.New1("userid=.[a-zA-Z0-9\-;]+")

is searching for "userid="then any combination of letters and numbers and "-" as the format of this cookie is "userid=87hjk-87dfsd-njdfh9-sldfkj4;" And once again I have included the ";" as it is at the end of every cookie.

if you google regex there are a number of very good sites that explain how to use them.
 
Last edited:

Byak@

Active Member
Licensed User
big thanks!
 

Byak@

Active Member
Licensed User
tnaks agraham
user_offline.gif
i'm find))
 

Byak@

Active Member
Licensed User
now i can get cookie correct.but now i must send it.
and how?
i'm use request.addheader("Cookie",cookie) but it doesnot work.

my cookie is
B4X:
remixlang=0; expires=Mon, 05-Oct-2009 20:38:26 GMT; path=/; domain=.vkontakte.ru,remixchk=5; expires=Mon, 05-Oct-2009 20:38:26 GMT; path=/; domain=.vkontakte.ru,remixchk=5; expires=Mon, 05-Oct-2009 20:38:26 GMT; path=/; domain=pda.vkontakte.ru,remixmid=18553027; expires=Mon, 05-Oct-2009 20:38:26 GMT; path=/; domain=pda.vkontakte.ru,remixemail=jendos-91%40mail.ru; expires=Mon, 05-Oct-2009 20:38:26 GMT; path=/; domain=pda.vkontakte.ru,remixpass=e10adc3949ba59abbe56e057f20f883e; expires=Mon, 05-Oct-2009 20:38:26 GMT; path=/; domain=pda.vkontakte.ru,remixcookietest=deleted; expires=Sat, 06-Oct-2007 20:38:25 GMT; path=/; domain=pda.vkontakte.ru
and before response.Value=request.GetResponse, response.Headers returns small pat of cookie...and server said "your browser doesn't receiv cookie"
how can i send cookie?
 

bish0p

Member
Licensed User
Longtime User
now i can get cookie correct.but now i must send it.
and how?
i'm use request.addheader("Cookie",cookie) but it doesnot work.

my cookie is
B4X:
remixlang=0; expires=Mon, 05-Oct-2009 20:38:26 GMT; path=/; domain=.vkontakte.ru,remixchk=5; expires=Mon, 05-Oct-2009 20:38:26 GMT; path=/; domain=.vkontakte.ru,remixchk=5; expires=Mon, 05-Oct-2009 20:38:26 GMT; path=/; domain=pda.vkontakte.ru,remixmid=18553027; expires=Mon, 05-Oct-2009 20:38:26 GMT; path=/; domain=pda.vkontakte.ru,remixemail=jendos-91%40mail.ru; expires=Mon, 05-Oct-2009 20:38:26 GMT; path=/; domain=pda.vkontakte.ru,remixpass=e10adc3949ba59abbe56e057f20f883e; expires=Mon, 05-Oct-2009 20:38:26 GMT; path=/; domain=pda.vkontakte.ru,remixcookietest=deleted; expires=Sat, 06-Oct-2007 20:38:25 GMT; path=/; domain=pda.vkontakte.ru
and before response.Value=request.GetResponse, response.Headers returns small pat of cookie...and server said "your browser doesn't receiv cookie"
how can i send cookie?

What your should equal
B4X:
cookie="remixlang=0; remixchk=5; remixmid=18553027; remixemail=jendos-91%40mail.ru; remixpass=e10adc3949ba59abbe56e057f20f883e; remixcookietest=deleted;"
 

Byak@

Active Member
Licensed User
very thnx!tomorrow i'm try
 
Top