HTTP POST with Qt 5.1.1



  • Hi...

    I'm porting code from Qt 4.8 to 5.1.1, but I'm a little confuse porting this code.

    I have something like this:

    @
    ...
    QUrl url = QUrl("www.something.com/some_file.php");
    QNetworkRequest network_request(url);
    ...
    QUrl request_parameters;

    request_parameters.addQueryItem("key1", QUrl::toPercentEncoding("value1"));
    request_parameters.addQueryItem("key2", QUrl::toPercentEncoding("value2"));
    request_parameters.addQueryItem("key3", QUrl::toPercentEncoding("value3"));
    ...
    QNetworkReply * network_reply = manager.post(network_request, request_parameters.encodedQuery());
    ...
    @

    How I port this code to 5.1.1 since addQueryItem is not a member of QUrl anymore?

    Ok... several people has the same problem, the solution they found, apparently is to use QUrlQuery for the parameters.

    So, in a similar way:

    @
    QUrlQuery request_parameters;

    request_parameters.addQueryItem("key1", QUrl::toPercentEncoding("value1"));
    request_parameters.addQueryItem("key2", QUrl::toPercentEncoding("value2"));
    request_parameters.addQueryItem("key3", QUrl::toPercentEncoding("value3"));
    @

    Is this right?

    After this, how I must call the post method with the new changes?

    Thanks in advance.


  • Moderators


Log in to reply
 

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