[Interest] QNetwork classes for submitting google forms

Nicholas Yue yue.nicholas at gmail.com
Fri Jun 11 22:22:12 CEST 2021


Hi,

I am trying to submit google forms programmatically via C++ and Qt classes

I am basing my study on the following

https://stackoverflow.com/questions/17964429/google-forms-response-with-python#17965510

I got the Python version running and returned a 200 response.

I tried converting the code to C++ and Qt but was not successful. I get a
response of '0' zero

I would like to know if I am using the Qt QNetwork classes correctly to
submit a post to a URL that is a Google form

=============================================================
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkAccessManager>
#include <QUrlQuery>
#include <QDebug>
#include <QNetworkReply>

int main()
{

    QUrlQuery postData;
    postData.addQueryItem("emailAddress", "abc.xyz at gmail.com");
    postData.addQueryItem("entry.2020959411", "Qt Query");

    /*
     *
    url = '
https://docs.google.com/forms/d/152CTd4VY9pRvLfeACOf6SmmtFAp1CL750Sx72Rh6HJ8/formResponse
'
    form_data = {'entry.2020959411': '18+ sollte absolute Pflicht sein',
                 #'entry.2020959411': 'Alter sollte garkeine Rolle spielen',
                 #'entry.2020959411': '17+ wäre für mich vertretbar',
                 #'entry.2020959411': '16+ wäre für mich vertretbar',
                 #'entry.2020959411': '15+ wäre für mich vertretbar',
                 #'entry.2020959411': 'Ausnahmen von der Regel - Dafür?',
                 #'entry.2020959411': 'Ausnahmen von der Regel - Dagegen?',
                 #'entry.2020959411': '__other_option__',
                 #'entry.2020959411.other_option_response': 'test',
                 'draftResponse': [],
                 'pageHistory': 0}     *
     */

    QUrl serviceUrl("
https://docs.google.com/forms/d/152CTd4VY9pRvLfeACOf6SmmtFAp1CL750Sx72Rh6HJ8/formResponse
");

    // ...
    QNetworkRequest request(serviceUrl);
    //request.setHeader(QNetworkRequest::ContentTypeHeader,
    //    "application/x-www-form-urlencoded");
    QNetworkAccessManager networkManager;
    QNetworkReply* reply;
    reply = networkManager.post(request,
postData.toString(QUrl::FullyEncoded).toUtf8());
    QVariant statusCode = reply->attribute(
QNetworkRequest::HttpStatusCodeAttribute );
    int status = statusCode.toInt();
    qDebug() << status;
    if ( status != 200 )
    {
        QString reason = reply->attribute(
QNetworkRequest::HttpReasonPhraseAttribute ).toString();
        qDebug() << reason;
    }

return 0;
}

-- 
Nicholas Yue
Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5
Custom Dev - C++ porting, OSX, Linux, Windows
http://au.linkedin.com/in/nicholasyue
https://vimeo.com/channels/naiadtools
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210611/df309b42/attachment.html>


More information about the Interest mailing list