0

我想用 POST 方法连接到一个网页,例如,所以我去登录页面“www.example.com/login”,在我成功登录后,我想去例如这里“www.example.com/index.php”但是我无法让它工作,因为无论我尝试什么,它仍然会返回“www.example.com/login”。

这是我的代码。

QNetworkAccessManager *manager;



 manager = new QNetworkAccessManager ();
     QNetworkRequest req;

address =("www.example/index.php");

        manager->setCookieJar(new QNetworkCookieJar);

        req.setHeader(req.UserAgentHeader,"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2");
        req.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
        req.setUrl(QUrl("www.example.com/login"));


            QByteArray postData;
            postData.append("login_user=user&");
            postData.append("login_passwd=Pass");

    connect (manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(writeToTxt(QNetworkReply  *)));



    manager->post(req, postData);
    manager->get(QNetworkRequest(address));

    manager->get(QNetworkRequest(QUrl("www.example.com/example.html")));

这是我的插槽

void HtmlSource::writeToTxt(QNetworkReply* reply)
{
    qDebug() << "atsakymas" << endl;
    if(reply->isOpen()){

        //qDebug() << reply->readAll();

            QFile file( "1.txt" );

        if ( file.open(QIODevice::ReadWrite) )
        {

            file.write(reply->readAll());
            file.close();

        }

    }
}
4

0 回答 0