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....@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
_______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest