Results 1 to 9 of 9

Thread: HTTP Post issue, HTML Works , QT Does Not,

  1. #1
    Join Date
    Nov 2010
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default HTTP Post issue, HTML Works , QT Does Not,

    Hello,

    I am trying to post a phone number to a forum and capture the returned bill data.

    I have an HTML form and when i use the form from the browser it works with the site.

    But when i try to do the post from QT somehow the site returns an error.

    please help, i dont know whats wrong, as the app does not error.

    please use phone number 51216855 in your test.

    i have attached my sample program and the actual form.

    webtest.zip

    if you have questions please contact me on skype georgeky4

  2. #2
    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: HTTP Post issue, HTML Works , QT Does Not,

    Your code quite happily fetches a result page here. What is wrong with it?

    The __VIEWSTATE and __EVENTVALIDATION parameters in the form sent from the server, and intended to be returned with the request, are probably specifically designed to prevent spoofing the form. If the valid HTML page returned is an error about security then this may well be the cause.

  3. #3
    Join Date
    Nov 2010
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HTTP Post issue, HTML Works , QT Does Not,

    no, these are fixed params, please see the html file that i have attached inside the project. it works perfectly and the returned page has the bill information. but the qt app, somehow gets an error page. i am guessing it has to do with a session cookie, but when i try to add it to qt app (a cookiejar) its breaking.

    i tested with raw HTML (included) also with a php curl and perl curl and all works well.

    just qt is the one returning an error page.

  4. #4
    Join Date
    Nov 2010
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HTTP Post issue, HTML Works , QT Does Not,

    Quote Originally Posted by georgeky View Post
    no, these are fixed params, please see the html file that i have attached inside the project. it works perfectly and the returned page has the bill information. but the qt app, somehow gets an error page. i am guessing it has to do with a session cookie, but when i try to add it to qt app (a cookiejar) its breaking.

    i tested with raw HTML (included) also with a php curl and perl curl and all works well.

    just qt is the one returning an error page.
    i tried this all day today, (added cookie jar) and tried looking at the headers using winshark and php/apache headers and live http header,

    everything seems to match, so this leavs ONLY the cookie not being accepted or handled. and somehow all i did with the cookiejar did not help.

    please any input is much appreciated.

  5. #5
    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: HTTP Post issue, HTML Works , QT Does Not,

    Show us how you used QNetworkCookieJar and how you went about getting the session cookie, which presumably included some form of authentication.

  6. #6
    Join Date
    Nov 2010
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HTTP Post issue, HTML Works , QT Does Not,

    Quote Originally Posted by ChrisW67 View Post
    Show us how you used QNetworkCookieJar and how you went about getting the session cookie, which presumably included some form of authentication.
    I think there was a confusion in what i said, I am not setting a cookie, the server is setting a cookie and i am assuming also is reading it back. based on what i understood, this is pretty much automatic when using QNetworkCookieJar.

    My latest code

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QUrl>
    4. #include <QtGui>
    5. #include <QtWebKit>
    6. #include <QNetworkAccessManager>
    7. #include <QDebug>
    8.  
    9. MainWindow::MainWindow(QWidget *parent) :
    10. QMainWindow(parent),
    11. ui(new Ui::MainWindow)
    12. {
    13. ui->setupUi(this);
    14. m_manager = new QNetworkAccessManager(this);
    15. m_manager->setCookieJar(new QNetworkCookieJar());
    16.  
    17. connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
    18.  
    19. }
    20.  
    21. MainWindow::~MainWindow()
    22. {
    23. delete ui;
    24. }
    25.  
    26.  
    27. void MainWindow::on_pushButton_clicked()
    28. {
    29. QUrl pUrl = QUrl("http://epay.ste.gov.sy/LandlineLogin.aspx");
    30. QString number=ui->lineEdit->text();
    31.  
    32. const char* USERAGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.1) Gecko/20100101 Firefox/6.0.1";
    33.  
    34. QNetworkRequest request;
    35.  
    36.  
    37. request.setUrl(pUrl);
    38.  
    39. request.setRawHeader("POST", "/LandlineLogin.aspx HTTP/1.1");
    40. request.setRawHeader("Host", "epay.ste.gov.sy");
    41. request.setRawHeader("User-Agent", USERAGENT);
    42. request.setRawHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    43. request.setRawHeader("Accept-Language","en-us,en;q=0.5");
    44. request.setRawHeader("Accept-Encoding","gzip, deflate");
    45. request.setRawHeader("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7");
    46. request.setRawHeader("Connection","keep-alive");
    47. request.setRawHeader("Content-Type","application/x-www-form-urlencoded");
    48. request.setRawHeader("Content-Length","300");
    49.  
    50.  
    51.  
    52.  
    53. QByteArray data;
    54. QUrl params;
    55.  
    56. params.addQueryItem("__VIEWSTATE", "/wEPDwUKMTYzOTMwODYxMGRkVEeVekMk3/sAdBfyPomrEotg83zpqXlu6s2KsGpNdDQ=");
    57. params.addQueryItem("__EVENTVALIDATION","/wEWBQKBt4mpDAKKo/qFAgLez+mJBAL07o6PBgKUiafMAYIx/ItiiybnhfcGZb1TAJ1J1fR3xF9e7rPxGcXQT59x");
    58. params.addQueryItem("ctl00$hdCulture","ar-SY");
    59. params.addQueryItem("ctl00$cphMain$txtPhoneNumber",number);
    60.  
    61. params.addQueryItem("ctl00$cphMain$btnLogin",number);
    62.  
    63. data.append(params.toString());
    64. //data.remove(0,1);
    65.  
    66.  
    67. qDebug() << "this data" << data;
    68.  
    69.  
    70.  
    71.  
    72.  
    73. m_manager->post(request,data);
    74.  
    75.  
    76.  
    77. }
    78.  
    79. void MainWindow::replyFinished(QNetworkReply* pReply)
    80. {
    81. QByteArray data=pReply->readAll();
    82. QString str(data);
    83. qDebug() << "this" << str.toAscii();
    84. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: HTTP Post issue, HTML Works , QT Does Not,

    If you are using wireshark, you should be able to easily notice if your program is sending back the cookie or not. By the way, I'm pretty much certain the thing you do with parameters of the request is wrong. Did you check what params.toString() returns? Is it compliant with the encoding you are declaring? Does content-length match?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    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: HTTP Post issue, HTML Works , QT Does Not,

    QUrl::encodedQuery() is worth a look for the data payload.

    At line 39 of your revised code: POST is not a header. The post() method generates this as the request line based on your URL. You also don't need to manually set the Host header or Content-Length headers; the post() method does that for you.

    Your cookie jar will be empty at start up. The server only sets a cookie when you GET the LandlineLogin.aspx page, so I put a GET request into the constructor and ignored the response. After that the POST request will send the cookie. I still get a 500 error from the server though.

    Inspection of the login page source and a wireshark dump of the value attached to the ctl00$cphMain$btnLogin parameter shows a binary blob ("Phone Bills Inquiry" in Arabic perhaps?) which you are not mimicking.
    Last edited by ChrisW67; 9th September 2011 at 01:38.

  9. #9
    Join Date
    Nov 2010
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HTTP Post issue, HTML Works , QT Does Not,

    I posted this as a job, in the job section, i cant make this dam post work with that site :-(

    If anyone is interested, please contact me on georgeky4
    http://www.qtcentre.org/threads/4452...ata-and-print.

Similar Threads

  1. HTTP POST / Proxy Authentication issue
    By dekc99 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2011, 10:59
  2. QT HTTP Post issue when server requires cookies
    By shadyabhi in forum Qt Programming
    Replies: 0
    Last Post: 22nd December 2010, 14:10
  3. HTTP POST method
    By Macok in forum Qt Programming
    Replies: 5
    Last Post: 25th July 2010, 15:33
  4. Http post
    By Max123 in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2010, 14:43
  5. Http Post method help
    By ravirdv in forum Qt Programming
    Replies: 0
    Last Post: 27th September 2009, 13:15

Tags for this Thread

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.