QNetworkReply * QNetworkAccessManager::sendCustomRequest ( const QNetworkRequest & request, const QByteArray & verb, QIODevice * data = 0 )
QUrl url("http://test.ru/...куда шлем"); QNetworkRequest request; request.setUrl(url); request.setRawHeader("Host", url.encodedHost()); request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)"); request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); request.setRawHeader("Accept-Language", "ru,en-us;q=0.7,en;q=0.3"); request.setRawHeader("Accept-Charset", "utf-8;q=0.7,*;q=0.7"); request.setRawHeader("Keep-Alive", "300"); request.setRawHeader("Connection", "keep-alive"); request.setRawHeader("Referer", "http:/test.ru/..откуда пришли"); request.setRawHeader("Cookie", "auth=NO"); request.setRawHeader("Content-Type", "text/xml"); QByteArray postData; postData.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "...твой запрос..."); QNetworkAccessManager *manager = new QNetworkAccessManager (this); QNetworkReply *reply = manager->post(request, postData); connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(getError(QNetworkReply::NetworkError)));
void .....::slotReadyRead(){ QNetworkReply *reply=qobject_cast<QNetworkReply*>(sender()); QNetworkAccessManager *manager=qobject_cast<QNetworkAccessManager *>(reply->manager()); int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (reply->error() == QNetworkReply::NoError) { //qDebug() << "================================="; //qDebug() << "status code: " << statusCode; switch (statusCode) { case 200: { QByteArray bytes = reply->readAll(); QString str(QString::fromUtf8(bytes)); ............. } } }}