Название: Запрос XML через QHttp Отправлено: Dolf85 от Июля 21, 2009, 15:22 Всем здарова!!! помогите плиз, возникла такая проблема, нужно сделать аутентификацию для получения xml с сервера, так вот у меня не получается даже запрос отправить чтобы получить хоть какой-то ответ через QHttp методом Post
Название: Re: Запрос XML через QHttp Отправлено: Dolf85 от Июля 21, 2009, 15:45 #include <QCoreApplication>
#include <QtNetwork> class MyHttp : public QHttp { Q_OBJECT public: MyHttp(const QString &host) : QHttp(host) { connect(this, SIGNAL(requestFinished(int, bool)), this, SLOT(finished(int, bool))); QHttpRequestHeader header("POST", "/xml.php"); header.setValue("Content-Type", "application/x-www-form-urlencoded"); header.setValue("Host", "http://"); request(header/*,inputStr, &f*/); } public slots: void finished(int requestid, bool error) { { QString *str = new QString; QChar *data = str->data(); while (*data != 0) { std::cout << (char *) data; ++data; } printf("\n"); } } }; #include "main.moc" int main(int argc, char** argv) { QCoreApplication a(argc, argv); MyHttp http("http://"); return a.exec(); } пытаюсь сделать вот так и не получается Название: Re: Запрос XML через QHttp Отправлено: whirlwind от Июля 21, 2009, 17:36 а как именно не получается? Url правильный?
Название: Re: Запрос XML через QHttp Отправлено: ритт от Июля 21, 2009, 18:07 Цитировать QString *str = new QString; вот это Ъ. запомню.QChar *data = str->data(); while (*data != 0) { std::cout << (char *) data; ++data; } Название: Re: Запрос XML через QHttp Отправлено: Rcus от Июля 21, 2009, 18:28 вот это Ъ. запомню. обфускатор в действии :)Название: Re: Запрос XML через QHttp Отправлено: Dolf85 от Июля 22, 2009, 07:36 Неужели никто не может помочь???
Название: Re: Запрос XML через QHttp Отправлено: Dolf85 от Июля 22, 2009, 08:13 а как именно не получается? Url правильный? запускаю приложение, а оно мне выдает Failed with an error и стоит так Название: Re: Запрос XML через QHttp Отправлено: zoro86 от Ноября 23, 2009, 13:16 Ну у меня все нормально работает... я через post отправляю
my_http = new QHttp(this); connect(my_http, SIGNAL(done(bool)), this, SLOT(slotReadyRead())); QHttpRequestHeader header = QHttpRequestHeader("POST", QString("/xml.php")); QString person="type=healthcase&recipient=test@test.com"; header.setValue("Host", strHost); my_http->setHost(strHost); my_http->request(header, "type=healthcase&recipient=test@test.com"); m_ptxtInfo = new QTextEdit; m_ptxtInput = new QLineEdit; connect(m_ptxtInput, SIGNAL(returnPressed()), this, SLOT(slotSendToServer()) ); m_ptxtInfo->setReadOnly(true); QPushButton* pcmd = new QPushButton("&Send"); connect(pcmd, SIGNAL(clicked()), SLOT(slotSendToServer())); //Layout setup QVBoxLayout* pvbxLayout = new QVBoxLayout; pvbxLayout->addWidget(new QLabel("<H1>Client</H1>")); pvbxLayout->addWidget(m_ptxtInfo); pvbxLayout->addWidget(m_ptxtInput); pvbxLayout->addWidget(pcmd); setLayout(pvbxLayout); } // ---------------------------------------------------------------------- void MyClient::slotReadyRead() { QTime time; QString str = my_http->readAll();; m_ptxtInfo->append(time.toString() + " " + str); } // ---------------------------------------------------------------------- void MyClient::slotSendToServer() { QByteArray ba("<?xml version=\"1.0\" encoding=\"UTF-8\"?><request>lalala</request></xml>"); my_http->post(QString("/xml.php"), ba); } |