PDA

View Full Version : QHttp - how should I connect?



Fenix Voltres
24th June 2009, 18:50
Hello,
I have a web page with (only) script which uses POST data. I want to write a program which would simply visit that page (without showing it / downloading / whatever) after clicking a button - so I wrote a function, which is called while clicking button:


QByteArray content("?id=1&etc=SomePostData");
QHttpRequestHeader header("POST", "/file.php");
header.setValue("Host", "www.hostname.com");
header.setContentType("application/x-www-form-urlencoded");
header.setContentLength(content.length());

QHttp *http = new QHttp("www.hostname.com", 80);
http->request(header, content);


and it actually does nothing :/
Would you tell me, what I've done wrong?
If i try to save that page into a file with request(header, content, &file) I got some error - program shuts down with window like uncatched exception one...

Thainks in an advance,
Fenix Voltres

wysota
25th June 2009, 08:25
I think you're using GET instead of POST in your data formatting, so use the GET method in the request as well. Anyway I'd suggest to use QNetworkAccessManager - it is much easier to use.

AcerExtensa
25th June 2009, 08:28
connect to
void stateChanged ( int state ) signal to debug what http do.
read data on
void QHttp::readyRead ( const QHttpResponseHeader & resp ) signal.

and try to set host.


http->setHost("www.hostname.com");

Fenix Voltres
25th June 2009, 11:15
I think you're using GET instead of POST in your data formatting, so use the GET method in the request as well. Anyway I'd suggest to use QNetworkAccessManager - it is much easier to use.

Of course - my mistake - this is GET. Anyway - this method doesn't work for me in this way...
But QNetworkAccessManager works perfectly well! Thanks much!