Results 1 to 17 of 17

Thread: Setting a cookie for a Qhttp connection

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Posts
    158
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    25

    Default Re: Setting a cookie for a Qhttp connection

    That's what I made last week .
    I think my post request is correct, but perhaps is there an authentification problem.
    The webmaster said me I was authenticated as an external user, and in this case the server unauthentificate me each time the connection is close (closing Firefox for example). So, perhaps, I'm unauthentificated cause I use 2 QHttp objetcs...

    I'll try to see that, and confirm that I'm correctly logged-in with the first request

  2. #2
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: Setting a cookie for a Qhttp connection

    Quote Originally Posted by Nyphel View Post
    That's what I made last week .
    I think my post request is correct, but perhaps is there an authentification problem.
    The webmaster said me I was authenticated as an external user, and in this case the server unauthentificate me each time the connection is close (closing Firefox for example). So, perhaps, I'm unauthentificated cause I use 2 QHttp objetcs...

    I'll try to see that, and confirm that I'm correctly logged-in with the first request

    if you have quote..
    If we have a look to the headers shown by the navigator, we can see that "/QDMSy9P" becomes "%2FQDMSy9P".
    http://www.blooberry.com/indexdot/ht...rlencoding.htm urldecode problem....
    if you grab cookie must decode and resend qstring can not decode url string!!

    Grab before post ... the form page .... on get method the form page .... to take phpsession code cookie ..
    i suppose if php can not init session your post is invalid! why session is not init!

    first ....
    1- QHttp get ( formpage_client ) take session PHPSESSIONID= xxxxxxxx
    and
    2- QHttp post ( form data ) +session + referrer ( PHPSESSIONID= xxxxxxxx ) cookie and param ...
    like firefox method....

    otherwise session on server not valid ASP have it a same mechanismous ... if the session ist not incomming server suppose a hack...

  3. The following user says thank you to patrik08 for this useful post:

    Nyphel (5th April 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,375
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Setting a cookie for a Qhttp connection

    Quote Originally Posted by Nyphel View Post
    The webmaster said me I was authenticated as an external user, and in this case the server unauthentificate me each time the connection is close (closing Firefox for example).
    I don't think this is the case. Closing a connection can happen without closing the browser - the server will close the connection about a few seconds without seeing another request coming, so you'd end up with the same effect in Firefox which I guess is not the case.
    When the browser closes, it may discard the cookie, but the server won't be notified about it, so this shouldn't influence your requests either.

  5. #4
    Join Date
    Feb 2007
    Posts
    158
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    25

    Default Re: Setting a cookie for a Qhttp connection

    You are true : my first request (the POST one, in order to be authentificated) is wrong.
    I got a cookie, but i was not logged-in.

    Moreover, my header content wasn't well written :
    Qt Code:
    1. QByteArray content = "";
    2. content.append("tr");
    3. content.append("=");
    4. content.append("login");
    5. content.append("login");
    6. content.append("=");
    7. content.append("login");
    8. content.append("referer");
    9. content.append("=");
    10. content.append("");
    11. content.append("nickname");
    12. content.append("=");
    13. content.append(identifiant);
    14. content.append("&");
    15. content.append("password");
    16. content.append("=");
    17. content.append(password);
    18. content.append("&");
    19. content.append("submit");
    20. content.append("=");
    21. content.append("Connexion");
    To copy to clipboard, switch view to plain text mode 
    Some "&" were missing !

    So here is my new content :
    Qt Code:
    1. QByteArray content = "";
    2.  
    3. content.append("tr");
    4. content.append("=");
    5. content.append("login");
    6. content.append("&");
    7. content.append("login");
    8. content.append("=");
    9. content.append("login");
    10. content.append("&");
    11. content.append("referer");
    12. content.append("=");
    13. content.append("http%3A%2F%2Fcourriel%2Findex.php");
    14. content.append("&");
    15.  
    16. content.append("nickname");
    17. content.append("=");
    18. content.append("Stagiaire");
    19. content.append("&");
    20. content.append("password");
    21. content.append("=");
    22. content.append("%2FQDMSy9P");
    23. content.append("&");
    24. content.append("lifetime");
    25. content.append("=");
    26. content.append("10000");
    27. content.append("&");
    28. content.append("submit");
    29. content.append("=");
    30. content.append("Connexion");
    To copy to clipboard, switch view to plain text mode 

    In order to prevent url encoding errors, wrote the "/" directly with "%2F".
    Now, my responseHeaderReceived() signal catch an error :
    statusCode = 302
    reasonPhrase = Found

    That's strange, cause the 302 error indicates that the Web server thinks that my URL has been temporarily redirected to another URL.

    Here is the full responseHeader :
    Qt Code:
    1. HTTP/1.1 302 Found
    2. date: Thu, 05 Apr 2007 12:55:23 GMT
    3. server: Apache/2.0.54 (Debian GNU/Linux) PHP/5.1.6-1~bpo.1 mod_ssl/2.0.54 OpenSSL/0.9.7e
    4. x-powered-by: PHP/5.1.6-1~bpo.1
    5. set-cookie: OV1274289294=b5ca1f5abaeea5cb6944080a88adc958; path=/
    6. expires: Thu, 19 Nov 1981 08:52:00 GMT
    7. cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    8. pragma: no-cache
    9. set-cookie: c_nickname=Stagiaire; expires=Thu, 05-Apr-2007 15:42:03 GMT
    10. set-cookie: c_password=a07390205157ca30543f2128de117385; expires=Thu, 05-Apr-2007 15:42:03 GMT
    11. location: http://courriel/index.php
    12. transfer-encoding: chunked
    13. content-type: text/html
    To copy to clipboard, switch view to plain text mode 

    Now, I'm logged in and everything is OK... If I don't care about the 302 error.
    So, I've you got an idea to explain why I get such error, please ?
    Last edited by Nyphel; 5th April 2007 at 15:11.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,375
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Setting a cookie for a Qhttp connection

    Should this script set those cookies (lines 9 and 10 of the above output) in that situation? You'd have to ask the script author what 302 means in this case It contains a redirection to index.php so looks like everything is fine, you should follow the location. It probably just redirects you to the proper page after login.

  7. The following user says thank you to wysota for this useful post:

    Nyphel (5th April 2007)

  8. #6
    Join Date
    Feb 2007
    Posts
    158
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    25

    Default Re: Setting a cookie for a Qhttp connection

    The cookies of lines 9 and 10 seems to be corresponding with the authentification... But I don't think they are usefull. I think that they are identifying the longgin session period.

    About the redirection :
    Qt Code:
    1. <form method="post" action="index.php">
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. <input type="hidden" name="referer" value="http%3A%2F%2Fcourriel%2Findex.php">
    To copy to clipboard, switch view to plain text mode 
    The redirection targets the same page as the form action .
    Ok, I will discuss about that with the webmaster.

    Thanks a lot Wysota and Patrick, now I understand better the cookies and how managing them with Qt4/ QHttp

Similar Threads

  1. QHttp internal error
    By LubosD in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2006, 10:57
  2. how to use QHttp inside QThread in Qt3
    By alusuel in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2006, 12:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.