Beispiel #1
0
void Codri::Resource::handleCompleteEvent(QxtWebRequestEvent *iEvent) {
    // Process all requests
    if (iEvent->method == "GET") {
        doGET(iEvent->sessionID, iEvent->requestID);
    } else if (iEvent->method == "DELETE") {
        doDELETE(iEvent->sessionID, iEvent->requestID);
    } else if (iEvent->method == "POST") {
        doPOST(iEvent->sessionID, iEvent->requestID, iEvent->content);
    } else if (iEvent->method == "PUT") {
        doPUT(iEvent->sessionID, iEvent->requestID, iEvent->content);
    } else {
        postUnsupportedMethod(iEvent->sessionID, iEvent->requestID);
    }
}
Beispiel #2
0
void ApiClient::report(HwScore const& score)
{
  // Construct the post data
  std::ostringstream oss;
  score.writeJson(&oss);
  AESCipher aes(commKey_);
  std::string cipher = aes.encrypt(oss.str());

  // Construct post action
  char action[128];
  std::string uuid_s;
  UnicodetoUTF8(score.uuid, &uuid_s);
  snprintf(action, sizeof(action), "/handin/report/%s/", uuid_s.c_str());

  // Do post
  std::string result = doPOST(action, cipher);
  if (result != "OK") {
    char exmsg[256];
    snprintf(exmsg, sizeof(exmsg), "Save result failed for handin(%s): %s.",
             uuid_s.c_str(), result.c_str());
    throw std::runtime_error(exmsg);
  }
}