reciving cookie.how?

Discussion in 'Questions (Windows Mobile)' started by Byak@, Sep 12, 2008.

  1. Byak@

    Byak@ Active Member Licensed User

    i aftorizizing in site
    Code:
    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(4096As 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?
     
  2. bish0p

    bish0p Member Licensed User

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

    Code:
    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

    Code:
    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

    Code:
    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.
     
  3. Byak@

    Byak@ Active Member Licensed User

    oh,thanks.but what is the regex?
     
  4. bish0p

    bish0p Member Licensed User

    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

    Code:
    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

    Code:
    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: Sep 12, 2008
  5. Byak@

    Byak@ Active Member Licensed User

    big thanks!
     
  6. agraham

    agraham Expert Licensed User

    It may be obvious but in bish0ps code "regex" is a Regex object from the Basic4ppc Regex library and "match" is a Match object from the same library.
     
  7. Byak@

    Byak@ Active Member Licensed User

  8. Byak@

    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
    Code:
    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?
     
  9. bish0p

    bish0p Member Licensed User

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

    Byak@ Active Member Licensed User

    very thnx!tomorrow i'm try
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice