Results 1 to 7 of 7

Thread: problems with Qhttp.

  1. #1
    Join Date
    Jan 2011
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default problems with Qhttp.

    I have 2 file php below:
    login.php
    Qt Code:
    1. <?
    2. session_start();
    3. ?>
    4. <FORM METHOD=POST>
    5. Password : <Input type = 'TEXT' Name ='password'> <INPUT TYPE=SUBMIT NAME="submit" VALUE="submit">
    6. </FORM>
    7. <?
    8. if(isset($_POST['submit'])){
    9. if(($_POST['password']) == "123456"){
    10. $_SESSION['login'] = "ADMIN";
    11. }else{
    12. $_SESSION['login'] = NULL;
    13. }
    14. ?>
    15. <SCRIPT languages="javascript">
    16. window.location = 'index.php';
    17. </SCRIPT>
    18. <?
    19. }
    20. ?>
    To copy to clipboard, switch view to plain text mode 
    index.php
    Qt Code:
    1. <?php
    2. session_start();
    3. if(isset($_SESSION['login'])){
    4. echo "ok";
    5. }else{
    6. echo "n-ok";
    7. }
    8. ?>
    To copy to clipboard, switch view to plain text mode 
    this is the class to send Post to login.php

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QHttp>
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. private:
    20. Ui::MainWindow *ui;
    21. QHttp *http;
    22. QHttp *secondHttp;
    23. QString cookie_value;
    24. private slots:
    25. void readResponseHeader(const QHttpResponseHeader &);
    26. void readSecondResponseHeader(const QHttpResponseHeader &);
    27. };
    28.  
    29. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. http = new QHttp("localhost", 80);
    10. secondHttp = new QHttp("localhost", 80);
    11. connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
    12. connect(secondHttp, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),this, SLOT(readSecondResponseHeader(const QHttpResponseHeader &)));
    13. QByteArray content = "";
    14. content.append("password");
    15. content.append("=");
    16. content.append("123456");
    17. content.append("&");
    18. content.append("submit");
    19. content.append("=");
    20. content.append("submit");
    21. QHttpRequestHeader header("POST", "/test/login.php");
    22. header.setValue("Host", "localhost");
    23. header.setContentType("application/x-www-form-urlencoded");
    24. header.setContentLength(content.length());
    25. http->request(header,content);
    26. }
    27.  
    28. void MainWindow::readResponseHeader(const QHttpResponseHeader &responseHeader){
    29. cookie_value = responseHeader.value("Set-Cookie");
    30. cookie_value = cookie_value.section(";", 0, 0);
    31. ui->textEdit->append(responseHeader.toString());
    32.  
    33. QHttpRequestHeader header("GET", "/test/index.php");
    34. header.setValue("Host", "localhost");
    35. header.setValue("Cookie", cookie_value);
    36. header.setContentType("application/x-www-form-urlencoded");
    37. secondHttp->request(header);
    38. }
    39.  
    40. void MainWindow::readSecondResponseHeader(const QHttpResponseHeader &responseHeader){
    41. ui->textEdit->append(responseHeader.toString());
    42. }
    43.  
    44. MainWindow::~MainWindow()
    45. {
    46. delete ui;
    47. delete http;
    48. delete secondHttp;
    49. }
    To copy to clipboard, switch view to plain text mode 

    The second time when send "GET" to index.php attach session code, run good
    The first time send request sever response :
    HTTP/1.1 200 OK
    Date: Fri, 25 Feb 2011 09:05:42 GMT
    Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9
    X-Powered-By: PHP/5.2.9
    Set-Cookie: PHPSESSID=2595a2b9578d54555be352faaa673feb; path=/
    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
    Content-Length: 214
    Content-Type: text/html
    The second time send request sever response :
    HTTP/1.1 200 OK
    Date: Fri, 25 Feb 2011 09:05:43 GMT
    Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9
    X-Powered-By: PHP/5.2.9
    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
    Content-Length: 2
    Content-Type: text/html
    But my isuisse is: how to get the content of index.php after send request
    (the content is ok or n-ok)
    Last edited by Con Nít; 25th February 2011 at 13:22.

  2. #2
    Join Date
    Jan 2011
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problems with Qhttp.

    somebody help me.
    thanks.


    Added after 26 minutes:


    I have solved my problem.
    Last edited by Con Nít; 26th February 2011 at 11:15.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problems with Qhttp.

    Another thing that comes to mind is why you are not using the cookie jar.

  4. #4
    Join Date
    Jan 2011
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problems with Qhttp.

    Quote Originally Posted by squidge View Post
    Another thing that comes to mind is why you are not using the cookie jar.
    In PHP, I can do that with CURLOPT_COOKIEJAR option, But I don't know how to do that with HTTP protocol, Could U edit directly in demo for me?

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problems with Qhttp.


  6. #6
    Join Date
    Jan 2011
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problems with Qhttp.

    I use responseHeader.allValues("Set-Cookie"); to get list cookie string type. How can I foist a list of cookies for the requests after that but no need use setValue instead of use QNetworkCookieJar.
    I don't understand QNetworkCookieJar's activity.
    Thanks for your help.

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: problems with Qhttp.

    You set the cookie jar on your QNetworkAccessManager and forget about it... or at least you would if you were not using the obsolete QHttp class.

Similar Threads

  1. problems in QHttp post method!
    By Longe.W in forum Qt Programming
    Replies: 6
    Last Post: 8th April 2009, 05:21
  2. Replies: 11
    Last Post: 20th January 2009, 14:10
  3. Problems with QHttp/s
    By zweieck in forum Qt Programming
    Replies: 0
    Last Post: 28th June 2008, 20:52
  4. Difference between QHttp::get and QHttp.request
    By LMZ in forum Qt Programming
    Replies: 2
    Last Post: 6th September 2007, 16:15
  5. QHttp has problems with some url's
    By whoops.slo in forum Qt Programming
    Replies: 2
    Last Post: 2nd June 2006, 23:16

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.