[Solved] QNetworkAccessManager createRequest post data



  • Hi,
    I have over ridden the createRequest function in QNetworkAccessManager but now i want to access the post form data that an html form submits is there any way i can do this. It's the data that is the second parameter in the post functions of QNetworkAccessManager, but i don't see how i can access it from the createRequest function ???
    Any help is much appreciated thanks.



  • Hi,

    • With createRequest() you create a new request where you have to define the type as the first parameter.

    for example;
    @Operation op = QNetworkAccessManager::PostOperation;@

    if you do this, is has the same effect as calling post() on the QNetworkAccessManager object.

    • the second parameter in createRequest() is the first parameter in post() -> QNetworkRequest

    • the third parameter in createRequest() is the second parameter in post() -> QIODevice * data
      in createRequest() this is default to 0 because this data atribute is only used if ther first parameter (Operation op) is defended as PostOperation or PutOperation, others don't use this data object...

    so, you have to put your data inside QIODevice * outgoingData = 0 when creating the request.

    where is our data coming from that you want to access? because if your run the function createRequest(), i suppose that your have the data somewhere, and want them to put in the request instead of trying to get it out ?



  • ok,
    I have an html form with some fields on it which are submitted when a user presses the submit button. I wish to validate this data in the QNetworkAccessManager. As far as i understand this should be the second parameter in the post function data. post then calls createRequest where my code is however i don't see how i can access the form data from the post function in the createRequest function. ??
    I don't create the request it comes from webkit when the user submits the form.



  • ok,

    I guess that the data is inside the QIODevice * outgoingData parameter...

    What do you receive if you do

    @
    QNetworkReply * MyNetworkAccessManager::createRequest(Operation op,
    const QNetworkRequest & req,
    QIODevice * outgoingData)
    {
    qDebug() << outgoingData->readAll();
    }
    @



  • Thank you very much thats exactly what i needed to know. the parameters are in the outgoingData QIODevice.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.