×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Get server cookie. NOT in Header!

    Hi all,
    I have discovered that the web server I am trying to reach mantains the sessions using three "custom" cookies.
    These are sent to the client after login. I need to receive these values and store them.
    After I succesfully do a login and receive a valid sessionID ("Set-Cookie") I need to send another request.
    These are the names of the three cookies
    vinixCookie[ID]
    vinixCookie[mail]
    vinixCookie[password]

    I now the mail but it seems ID is server generated and the password looks encripted.
    If I do a
    c.getRequestProperty("vinixCookie[ID]");
    I receive a null...

    How do I get these values hold them and send them to the server with my requests?

  2. #2
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Re: Get server cookie. NOT in Header!

    Nokia???
    Do I have to assume it's not possible to read a cookie sent by the web server?

  3. #3
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: Get server cookie. NOT in Header!

    Here's an article about cookie management that can be of some help:

    http://www.javaworld.com/javaworld/j...26-cookie.html

    Pit

  4. #4
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Re: Get server cookie. NOT in Header!

    I already had that article but probably didn't read it through.
    I am not getting the answer from the server (the 302 response that redirect to welcome.php) that holds the set-cookie I need..

    This is what happens:
    loginUser.php with login info receive a HTTP 200 OK ret code
    a welcome.php is opened (this has the cookie info I need to register)
    after a few seconds a redirect to an index.php is performed

    This is a log of HTTP monitor
    Code:
    POST /logUser.php HTTP/1.1
    Accept: */*
    Referer: http://www.vinix.it/login.php
    Accept-Language: it
    Content-Type: application/x-www-form-urlencoded
    UA-CPU: x86
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
    Host: www.vinix.it
    Content-Length: 86
    Connection: Keep-Alive
    Cache-Control: no-cache
    Cookie: PHPSESSID=7d1caa5e92e57159996ac5fb1cae3b55; __utma=233413529.929838416.1209659074.1209682496.1209728277.4; __utmz=233413529.1209659074.1.1.u
    
    HTTP/1.1 302 Found
    Date: Fri, 02 May 2008 11:38:55 GMT
    Server: Apache
    X-Powered-By: PHP/5.1.6
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Pragma: no-cache
    Set-Cookie: vinixCookie[mail]=i----------; expires=Sun, 01-Jun-2008 11:38:55 GMT
    Set-Cookie: vinixCookie[ID]=2----; expires=Sun, 01-Jun-2008 11:38:55 GMT
    Set-Cookie: vinixCookie[pw]=c33e--------------------; expires=Sun, 01-Jun-2008 11:38:55 GMT
    Location: welcome.php
    Content-Length: 0
    Connection: close
    Content-Type: text/html
    
    GET /welcome.php HTTP/1.1
    Accept: */*
    Referer: http://www.vinix.it/login.php
    Accept-Language: it
    UA-CPU: x86
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
    Host: www.vinix.it
    Connection: Keep-Alive
    Cache-Control: no-cache
    Cookie: PHPSESSID=7d1caa5e92e57159996ac5fb1cae3b55; vinixCookie[mail]=info%40......it; vinixCookie[ID]=26112; vinixCookie[pw]=c...............................a21670dc; __utma=233413529.929838416.1209659074.1209682496.1209728277.4; __utmz=233413529.1209659074.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); __utmb=233413529; __utmc=233413529

  5. #5
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Re: Get server cookie. NOT in Header!

    So the article didn't help I am still stuck with this problem.
    Any idea on how to get those cookies?

  6. #6
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Re: Get server cookie. NOT in Header!

    If this can help here is the code inside the login.php of the form for the login
    Code:
    <form action="logUser.php" method="post" name="formLogin" id="formLogin">
                          <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td align="left" nowrap class="text_11" style="padding-right:15px; padding-left:10px">e-mail</td>
                              <td align="left" valign="bottom"><input name="email" type="text" class="moduloBig" id="email" style="width:130px" value=""></td>
                            </tr>
                            <tr>
                              <td height="3" colspan="2"></td>
                            </tr>
                            <tr>
                              <td align="left" nowrap class="text_11" style="padding-right:15px; padding-left:10px">password</td>
                              <td align="left" valign="bottom"><input name="password" type="password" class="moduloBig" id="password" style="width:130px"></td>
                            </tr>
                            <tr>
                              <td height="5" colspan="2"></td>
                            </tr>
                            <tr>
                              <td>&nbsp;</td>
                              <td><input name="submit1" type="image" id="submit1" src="images/bt_invia_2_ita.gif" border="0">                                
                                <input name="type" type="hidden" id="type" value="">
                                    <input name="command" type="hidden" id="command" value="login">
                                    <script language="JavaScript" type="text/JavaScript">
    								document.formLogin.email.focus();
                                  </script></td></tr>
                            <tr>
                              <td colspan="2">&nbsp;</td>
                              </tr>
                            <tr>
                                        <td colspan="2" class="text_11_green" style="padding-left:10px"><b>Non sei registrato ?</b><br>
                                  <a href="registrazione.php"><u>Registrati adesso</u></a></td>
                              </tr>
                          </table>
                        </form>

  7. #7
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Talking Re: Get server cookie. NOT in Header!

    SOLVED!

    First of all there is, of course, no property cookie VinixCookie so I have to parse Set-Cookie property.
    I have to include a command=login in the parameter passed and have to pass the parameters as bytes to be written in the outputstream. Also do not include a "?" in the address of the action script.
    Last I had to include a Referer proprty of the page that included the form.

    Maybe a few of these are useless but now it works...

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    69

    Re: Get server cookie. NOT in Header!

    hi sandro1972, congratulation!
    From my tries and previous topic, seems the s60 SDK HTTP API doesn't support to read multi set-cookies. I wonder how to read those 3 cookies out from one responds message. It's very important for my work on hand. Thank you.
    Last edited by xuelanding; 2008-06-24 at 06:32.

  9. #9
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Re: Get server cookie. NOT in Header!

    Hi,
    are you trying to get the cookies from Vinix? or is it another site?

    Anyway you probably get the cookies all in one line so you have to parse the set-cookie and get the values of the three cookies. Bare in mind that this will work or not depending on the handset. So you'll have to program both logics (3 set-cookies and 1 set-cookie to be parsed).

    Alex

  10. #10
    Registered User
    Join Date
    Apr 2008
    Posts
    69

    Re: Get server cookie. NOT in Header!

    Alex,
    I'm not using vinik. But the multi-cookies are seting in one response header same as that in your http log.

    I don't know how can you get all 3 cookies in one line. Can you share me some code?

    With following code to read cookie, I can only got the first cookie name and cookie value:
    {
    HBufC8* my_cookie_name;
    HBufC8* my_cookie_value;

    RHTTPResponse resp = aTransaction.Response();
    RHTTPHeaders headers = resp.GetHeaderCollection();
    RStringPool string_pool = iSession.StringPool();


    {
    RStringF set_cookie_rsf = string_pool.StringF(HTTP::ESetCookie, RHTTPSession::GetTable());
    TInt strparts=headers.FieldPartsL(set_cookie_rsf);

    THTTPHdrVal field_value;

    if (headers.GetField(set_cookie_rsf, 0, field_value) == KErrNone)
    {
    RStringF cookie_rsf = string_pool.StringF(HTTP::ECookie, RHTTPSession::GetTable());

    if (field_value.StrF() == cookie_rsf)//??
    {
    RStringF cookie_value_rsf = string_pool.StringF(HTTP::ECookieValue, RHTTPSession::GetTable());
    RStringF cookie_name_rsf = string_pool.StringF(HTTP::ECookieName, RHTTPSession::GetTable());
    THTTPHdrVal cookie_hdr;
    if (!headers.GetParam(set_cookie_rsf, cookie_value_rsf, cookie_hdr))
    {
    RStringF rsf = string_pool.StringF(cookie_hdr.StrF());
    text.Copy(rsf.DesC());


    }
    if (!headers.GetParam(set_cookie_rsf, cookie_name_rsf, cookie_hdr))
    {
    RStringF rsf = string_pool.StringF(cookie_hdr.StrF());
    text.Copy(rsf.DesC());

    }
    }
    }
    }


    Thank you!

    Landing

  11. #11
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Re: Get server cookie. NOT in Header!

    Hi,
    I am not familiar with C/C++ (I am getting into objective-C soon) but as I understand you are reading the headers look for Set-Cookie and pass the value to cookie_value_rsf.
    In my HttpResponse this value would have all the 3 cookies named VinixMail=..., VinixID=... and VinixPWD=....
    So what I do I parse cookie value for the three cokie values.

    [forget my naming I know it's so bad]
    Code:
                        if (c.getHeaderFieldKey(k).equalsIgnoreCase("set-cookie")) {
                            String a = c.getHeaderField(k);
                            if (a.startsWith(this.vinixPWcookie)) {
                                this.vinixCookiePW = a.substring(vinixPWcookie.length(), a.indexOf(";"));
                            }
    
                            if (a.startsWith(this.vinixIDcookie)) {
                                this.vinixCookieID = a.substring(vinixIDcookie.length(), a.indexOf(";"));
                            }
    
                            if (a.startsWith(this.vinixMLcookie)) {
                                this.vinixCookieMail = a.substring(vinixMLcookie.length(), a.indexOf(";"));
                                if (a.indexOf(this.vinixPWcookie) > 0) {
                                    this.vinixCookiePW = a.substring((a.indexOf(this.vinixPWcookie) + vinixPWcookie.length()), a.indexOf(";", (a.indexOf(this.vinixPWcookie) + vinixPWcookie.length())));
                                }
                                if (a.indexOf(this.vinixIDcookie) > 0) {
                                    this.vinixCookieID = a.substring((a.indexOf(this.vinixIDcookie) + vinixIDcookie.length()), a.indexOf(";", (a.indexOf(this.vinixIDcookie) + vinixIDcookie.length())));
                                }
                            }
    
                        }
    If I have 3 set-cookie the first 3 "if" statements will get the values otherwise I look into the set-cookie for the string VinixPWD if this is not at the beginning it means the set-cookie holds the 3 cookies in the same value so I parse it and get the three separate cookies from the same set-cookie value.
    This, at least, works for me on Nokia headsets (I have problems with Motorola but I am still not sure why, and anyway is not on this piece of code).

    Cheers

    Alex

  12. #12
    Registered User
    Join Date
    Apr 2008
    Posts
    69

    Re: Get server cookie. NOT in Header!

    Alex,
    Thanks for your reply. But I still can't get multi cookies set by server in one line in my code. What API are you using?
    Maybe I can only parse the http header by myself based on tcp/ip socket.

    Thanks any way.
    Landing

  13. #13
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    75

    Re: Get server cookie. NOT in Header!

    I use
    javax.microedition.io.HttpConnection

    and the call the getHeaderField() and getHeaderFieldKey()

    I first use a while() to go through every getHeaderFiedlKey(int i) untill this call returns null
    if this is a set-cookie I check if it's a valid cookie.

    if this doesn't work it's probably a good idea to change the way you read the headers...

    Sorry

  14. #14
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Re: Get server cookie. NOT in Header!

    Hello,

    related: a Known Issue in Java:

    http://wiki.forum.nokia.com/index.ph...not_be_handled

    Regards,
    r2j7
    [URL="http://library.forum.nokia.com/java"][B] >>> Java Developer's Library <<<[/B][/URL]
    [URL="https://www.developer.nokia.com/Resources/Support/Technical_support.xhtml"] [B]>>> Technical Support for Java ME development <<<[/B][/URL]
    [URL="https://publish.ovi.com/info/"][B]>>> Nokia Publish: reach millions of Nokia users worldwide through Nokia Store <<<[/B][/URL]

  15. #15
    Registered User
    Join Date
    Apr 2008
    Posts
    69

    Re: Get server cookie. NOT in Header!

    r2j7, is this known issue appliable to the C++ SDK?

Similar Threads

  1. j2se server j2me client bluetooth connection problem
    By bepolat in forum Mobile Java Networking & Messaging & Security
    Replies: 6
    Last Post: 2010-07-14, 11:05
  2. reading cookie value from header
    By yazwas in forum Symbian
    Replies: 0
    Last Post: 2007-11-19, 10:45
  3. socket server application using Series 60 SDK
    By irohit in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2004-09-16, 05:27
  4. Nokia Presence Server
    By laurapacini in forum General Messaging
    Replies: 1
    Last Post: 2003-05-26, 13:42
  5. Programatically starting a custom server
    By GJokiel in forum Symbian
    Replies: 1
    Last Post: 2003-05-19, 10:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •