QString Client::sendData(const QString &data) {
//    qDebug() << "send to url => " << mUrl << " | data => " << data;
    QHttp http;
    http.ignoreSslErrors();
    QUrl url(mUrl);
    http.setHost(url.host());
    http.post(url.path(), data.toUtf8());
    waitForFinish(http);
    if(http.error() != QHttp::NoError) {
        return "";
    }
    return QString(http.readAll());
}
Exemple #2
0
int CyclopsMaster::sendSlaveRequest(const QPair<QHostAddress, int>& slave, const yaml::Mapping& request) {
  QHttp* slaveRequest = new QHttp(slave.first.toString(), slave.second, this);

  // connect the reply from this slave to the replyFromSlave method
  connect(slaveRequest, SIGNAL(requestFinished(int,bool)),
          this, SLOT(replyFromSlave(int,bool)));

  QBuffer* replyData = new QBuffer();
  int connid = slaveRequest->post("/", QByteArray("q=") + yaml::dump(request), replyData);

  // make sure this ID doesn't already exist, otherwise we're toast...
  if (_slaveReplies.contains(connid)) {
    throw GaiaException("2 slaves connections have the same ID, impossible to go on like that...");
  }

  _slaveReplies.insert(connid, replyData);
  return connid;
}