How can I POST data to a url using QNetworkAccessManager

后端 未结 6 1938
北荒
北荒 2020-11-30 22:33

I have a webservice that I need to POST some data to using Qt. I figured that I can use a QByteArray when POSTing to the web service.

My question is, how can I forma

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 22:45

    Here is another way to handle this, i am using your code also to give a complete code:

         // Setup the webservice url         
         QUrl serviceUrl = QUrl("http://myserver/myservice.asmx");
         QByteArray postData;
    
         QUrl params;
         params.addQueryItem("param1","string1");
         params.addQueryItem("param2","string2");
    
         postData = params.encodedQuery();
    
         // Call the webservice
         QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
         connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(serviceRequestFinished(QNetworkReply*)));
    
          networkManager->post(QNetworkRequest(serviceUrl), postData);
    

提交回复
热议问题