Re: QHttp Post work inkorect
Are we supposed to diff those two files ourselves to see the difference between them?
Re: QHttp Post work inkorect
Head is the same , but body is different . Look on line cout
But the content is not important. Why this post request doesn't work correctly ??
Re: QHttp Post work inkorect
We have no idea what you mean by that it doesn't work correctly. What is correct in this case?
Re: QHttp Post work inkorect
Post request is the same in Qt and in curl, but correct result is only in curl. Qt give wrong result, like paramtrs ware wrong (but i use the same parametrs in both cases).
Re: QHttp Post work inkorect
And what kind of help do you expect from us? Apparently the two requests differ so take a network sniffer and find the difference.
Re: QHttp Post work inkorect
I want from you to show me how correct configure POST request in QT, because now is somting wrong , the same result i get if i use GET request. Curl show correct result (using this parametrs "name=Gaths&password=qwerasdf&lowRes=1&login=13592 99878&w=") maybe in Qt is different way to do this
Re: QHttp Post work inkorect
Get a network sniffer such as wireshark and find out differences between the two requests.
Re: QHttp Post work inkorect
but i know, that parametrs are good and should work "name=Gaths&password=qwerasdf&lowRes=1&login=1 3592 99878&w="
name=Gaths
password=qwerasdf
lowRes=1
login=13592 99878
w=
And work, but in qt dont work :( (i do something wrong but i dont know what)
Re: QHttp Post work inkorect
Get a network sniffer and find out differences between two requests. You are comparing unencoded body of the request which says nothing about what gets sent to the server. Don't guess what gets sent, check it using tools available. You will see many differences between the two requests, you need to find those that matter (e.g. content encoding header) and correct your request. Your "problem" comes from your apparent limited knowledge about HTTP so either you learn how HTTP works or you mimic a working request. The latter is certainly faster than the former, however you learn much more from the former than the latter.
Re: QHttp Post work inkorect
thx for help (i use wireshark), i know what is wrong, it is problem with encoding.
POST parametrs from firefox IN WIRESHARK look like this:
"name=Gaths&password=qwerasdf&s1=Login&w=1024%3A60 0&login=1359443665"
but from qt POST look like this:
"6e616d234567843234356445678956774343..."
Can somebody tell me how correctli encode parametrs in qt ?? (my app code is in first post)
Re: QHttp Post work inkorect
You need to provide proper encoding for the data.
http://en.wikipedia.org/wiki/POST_(HTTP)
It should probably be x-www-form-urlencoded but it looks like base64 now.
And by the way, I suggest you use QNetworkAccessManager rather than QHttp which has been deprecated for years.
Re: QHttp Post work inkorect
i change QHttp to QNetworkAccessManager and set base64 but still dont work ;(
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
networkManager = new QNetworkAccessManager(this);
connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestFinished(QNetworkReply*)));
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(send()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::send()
{
postData.append("name=Gaths&");
postData.append("password=qwerasdf&");
postData.append("s1=Login&");
postData.append("w=1024%3A600&");
postData.append("login=1359443665");
networkManager
->post
(QNetworkRequest
(QUrl("http://ts9.travian.pl/dorf1.php")), postData.
toBase64());
}
void MainWindow::requestFinished(QNetworkReply *reply)
{
if(reply->isOpen())
{
ui->plainTextEdit->setPlainText(reply->readAll());
reply->close();
}
}
If i set postData.toBase64() or just postData, result its the same , in wireshark write "Media Type: application/octet-stream 67 bytes", but should by "Line-based text data: application/x-www-form-urlencoded" .
How i can convert postData to x-www-form-urlencoded.
WORKKKKK!!!!!
Code:
void MainWindow::send()
{
postData.addQueryItem("name", "Gaths");
postData.addQueryItem("password","qwerasdf");
postData.addQueryItem("s1","Login");
postData.addQueryItem("w","1024%3A600");
postData.addQueryItem("login","1359443665");
QNetworkRequest request
(QUrl("http://ts9.travian.pl/dorf1.php"));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
networkManager->post(request, postData.encodedQuery());
}
THX for help