1 Attachment(s)
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.
Attachment 6823
if you have questions please contact me on skype georgeky4
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.
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.
Re: HTTP Post issue, HTML Works , QT Does Not,
Quote:
Originally Posted by
georgeky
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.
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.
Re: HTTP Post issue, HTML Works , QT Does Not,
Quote:
Originally Posted by
ChrisW67
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
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QUrl>
#include <QtGui>
#include <QtWebKit>
#include <QNetworkAccessManager>
#include <QDebug>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_manager = new QNetworkAccessManager(this);
m_manager->setCookieJar(new QNetworkCookieJar());
connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QUrl pUrl
= QUrl("http://epay.ste.gov.sy/LandlineLogin.aspx");
QString number
=ui
->lineEdit
->text
();
const char* USERAGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.1) Gecko/20100101 Firefox/6.0.1";
QNetworkRequest request;
request.setUrl(pUrl);
request.setRawHeader("POST", "/LandlineLogin.aspx HTTP/1.1");
request.setRawHeader("Host", "epay.ste.gov.sy");
request.setRawHeader("User-Agent", USERAGENT);
request.setRawHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
request.setRawHeader("Accept-Language","en-us,en;q=0.5");
request.setRawHeader("Accept-Encoding","gzip, deflate");
request.setRawHeader("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7");
request.setRawHeader("Connection","keep-alive");
request.setRawHeader("Content-Type","application/x-www-form-urlencoded");
request.setRawHeader("Content-Length","300");
params.addQueryItem("__VIEWSTATE", "/wEPDwUKMTYzOTMwODYxMGRkVEeVekMk3/sAdBfyPomrEotg83zpqXlu6s2KsGpNdDQ=");
params.addQueryItem("__EVENTVALIDATION","/wEWBQKBt4mpDAKKo/qFAgLez+mJBAL07o6PBgKUiafMAYIx/ItiiybnhfcGZb1TAJ1J1fR3xF9e7rPxGcXQT59x");
params.addQueryItem("ctl00$hdCulture","ar-SY");
params.addQueryItem("ctl00$cphMain$txtPhoneNumber",number);
params.addQueryItem("ctl00$cphMain$btnLogin",number);
data.append(params.toString());
//data.remove(0,1);
qDebug() << "this data" << data;
m_manager->post(request,data);
}
void MainWindow::replyFinished(QNetworkReply* pReply)
{
qDebug() << "this" << str.toAscii();
}
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?
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.
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.