How can I create a HTTP POST request with Qt 4.6.1?

前端 未结 2 1205
面向向阳花
面向向阳花 2020-12-15 15:59

How can I create a HTTP POST request with some URL encoded parameters using Qt 4.6.1?

I figured out that I can create a QNetworkRequest, set all the parameters there

相关标签:
2条回答
  • 2020-12-15 16:43

    I'm sorry that I only find your post this late. However, I'll still try to help, in case anyone else is searching for the answer.

    By accident, I'm also working on an EVE API application, and I also tried the same way. Unfortunately, QNetworkManager doesn't work that way, because it posts the request asynchronously. You have to connect a slot to its finished(QNetworkReply*) signal.

    I do it by making a request with a separate class called EveConnector, processing the reply in the slot connected to the QNetworkManager's finished signal, and then calling back the requesting object through the connector class's own signals.

    I would happily share the code, if you ask.

    0 讨论(0)
  • 2020-12-15 16:49

    Your solution is almost right. But one should use:

    data = params.encodedQuery();
    

    instead of

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

    to handle UTF8 strings properly.

    0 讨论(0)
提交回复
热议问题