int HttpUploader::upload(const StringBuffer& luid, InputStream* inputStream) { int status = 0; // safe checks if (!inputStream || !inputStream->getTotalSize()) { LOG.error("upload error: no data to transfer"); return 1; } if (luid.empty() || syncUrl.empty() || sourceURI.empty()) { LOG.error("upload error: some params are not set"); return 2; } StringBuffer fullUrl = composeURL(); URL url(fullUrl.c_str()); HttpConnection* httpConnection = getHttpConnection(); httpConnection->setCompression(false); status = httpConnection->open(url, HttpConnection::MethodPost); if (status) { delete httpConnection; return status; } httpConnection->setKeepAlive(keepalive); httpConnection->setRequestChunkSize(maxRequestChunkSize); // Set headers (use basic auth) HttpAuthentication* auth = new BasicAuthentication(username, password); httpConnection->setAuthentication(auth); setRequestHeaders(luid, *httpConnection, *inputStream); // Send the HTTP request StringOutputStream response; status = httpConnection->request(*inputStream, response); LOG.debug("response returned = %s", response.getString().c_str()); // Manage response headers if (useSessionID) { // Server returns the jsessionId in the Set-Cookie header, can be used for // the subsequent calls of upload(). StringBuffer hdr = httpConnection->getResponseHeader(HTTP_HEADER_SET_COOKIE); sessionID = httpConnection->parseJSessionId(hdr); } httpConnection->close(); delete auth; delete httpConnection; return status; }
void CommInterfaceJson::getAccount() { // muodostetaan request const QString urlString = mApiUrl.toString() + "/account"; QNetworkRequest request( QUrl::fromUserInput( urlString ) ); setRequestHeaders( &request ); // odotetaan vastausta ResponseData rData; rData.response = mNetworkManager->get(request); rData.function = GW_GET_ACCOUNT; mReplyVector.push_back( rData ); }