How can i Post the data in QtCreator?

青春壹個敷衍的年華 提交于 2019-12-02 12:20:40

I will post a piece of code from my own program. Hopefully this will help:

void MainWindow::sendPost(url)
{
    QUrl params;
    params.addQueryItem("usrname", login);
    params.addQueryItem("passwrd", password);

    QByteArray data;
    data.append(params.toString());
    data.remove(0,1);

    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    QNetworkReply *reply = manager->post(QNetworkRequest(url), data);
    CONNECT(reply, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
}

void MainWindow::replyFinished(QNetworkReply *reply)
{
 QString data = reply->readAll().trimmed();
 qDebug() << data;
} 

PHP code will get values from program using $_POST array ($_POST['usrname'] and $_POST['password'] hold both values sent from the program), not $_SERVER. I have no idea why did you use $_SERVER.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!