Discussion Board

Results 1 to 10 of 10

Thread: XHR and Cookies

  1. #1
    Regular Contributor florianhaar's Avatar
    Join Date
    Aug 2009
    Posts
    50
    Hello everyone,

    can someone tell me, how I can send Cookies to a Server with XHR?

    I read this site
    http://wiki.forum.nokia.com/index.ph...s_and_with_XHR,
    but I don't really understand how I can use it.

    Hope someone can help me.

    thanx

    florianhaar

  2. #2
    Nokia Developer Champion jappit's Avatar
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,391
    Hi florianhaar,

    I've not tested cookies within WRT widgets yet, anyway from this Wiki article it seems that widgets automatically manage cookies when loading HTTP resources via XMLHttpRequest, so you have not to do anything else to manage them.

    Have you already tried to use them in your widget? Are you experiencing any specific issues?

    Pit

  3. #3
    Regular Contributor florianhaar's Avatar
    Join Date
    Aug 2009
    Posts
    50
    Hi jappit,

    I tested document.cookie. But know I need to send this cookie to the server with xmlhttprequest. But I don't know how I can do it.

    Hope you or someone can help me.

    thanx
    florianhaar

  4. #4
    Nokia Developer Champion jappit's Avatar
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,391
    The Wiki article says that you cannot access Cookies via JavaScript in WRT widgets. Anyway, your server should (theoretically) be able to read them without any JavaScript code: have you checked this on the server side?

    Pit

  5. #5
    Regular Contributor florianhaar's Avatar
    Join Date
    Aug 2009
    Posts
    50
    ok, but how does the server know that i have a cookie or not.
    It does not get in my mind.
    sorry

  6. #6
    Nokia Developer Champion jappit's Avatar
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,391
    Cookie management is inbuilt in browsers, and cookies' information is transferred to the remote server (in the subsequent HTTP requests) without the need to manually send it via JavaScript. So, WRT widgets should work the very same way (I say 'should' as I've not tested this by myself).

    You can find a lot of introductions and info about cookies on the net, as this:

    http://en.wikipedia.org/wiki/HTTP_cookie

    Pit

  7. #7
    Regular Contributor florianhaar's Avatar
    Join Date
    Aug 2009
    Posts
    50
    thank you again jappit i would look and test.

    florianhaar

  8. #8
    Regular Contributor florianhaar's Avatar
    Join Date
    Aug 2009
    Posts
    50
    Hello again,
    I found that i must use this:

    var client = new XMLHttpRequest();

    client.open("POST", url, false);
    client.setRequestHeader("Cookie"," test=tests");

    client.onreadystatechange = function() {
    if(client.readyState == 4 && client.status == 200){
    alert(client.getAllResponseHeaders());
    document.getElementById('test').innerHTML = client.responseText;
    }
    }

    to set a cookie, but that doesn't work.

    So what is wrong, or does the WRT not work with cookies allright?

    Can someone help?

    thanx

    florianhaar

  9. #9
    Nokia Developer Champion jappit's Avatar
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,391
    Hi florianhaar,

    I've just done a quick test, and I wasn't unable to get cookies working in a WRT widget.

    I've set up two pages:

    1) http://www.jappit.com/m/wrt/cookies/cookie_set.php - sends the cookie to th client
    2) http://www.jappit.com/m/wrt/cookies/cookie_get.php - read back and displays the cookie from the client

    Calling 1) and 2) from the browser, the cookie is correctly set and read back. Anyway, in the WRT widget (on real device) it doesn't seem to work (the test widget is available here: http://www.jappit.com/m/wrt/cookies/CookieTest.wgz)

    Will let you know if I find any working solutions,
    Pit

  10. #10
    Regular Contributor florianhaar's Avatar
    Join Date
    Aug 2009
    Posts
    50
    Thank you very much.
    It helps. Now I know that the WRT can't send cookies. That is bad, but I don't can do anything. So now I need another way to send my informations.

    Thanx
    florianhaar

Similar Threads

  1. cookies
    By lilin1lilin in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2010-04-22, 03:28
  2. XHR Qt webkit
    By pgattu in forum Qt
    Replies: 1
    Last Post: 2010-04-05, 11:08
  3. cookies...
    By themainman in forum General Development Questions
    Replies: 0
    Last Post: 2005-10-26, 14:51
  4. Cookies
    By ndorphine in forum Mobile Web Site Development
    Replies: 4
    Last Post: 2003-09-04, 00:04
  5. Cookies
    By Nokia_Archive in forum Mobile Web Site Development
    Replies: 1
    Last Post: 2002-05-15, 18:43

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved