curl returning none of the HTML content
-
Hi, I'm having a problem with curl, the content of the HTML being written is: "".
I believe that the problem is related to the installation since the same code works perfectly in visual studio code.My curl installation:
QT += core gui sql greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 LIBS += "C:/Users/uique/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Qt/6.4.0/MinGW 11.2.0 (64-bit)/lib/libcurl.a" LIBS += "C:/Users/uique/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Qt/6.4.0/MinGW 11.2.0 (64-bit)/lib/libcurl.dll.a" INCLUDEPATH += "C:/Users/uique/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Qt/6.4.0/MinGW 11.2.0 (64-bit)/includer/curl" SOURCES += \ add_order.cpp \ login.cpp \ main.cpp \ mainwindow.cpp \ wallet.cpp HEADERS += \ Global_variables.h \ add_order.h \ login.h \ mainwindow.h \ wallet.h FORMS += \ add_order.ui \ login.ui \ mainwindow.ui \ wallet.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target RESOURCES += \ Resources.qrc
my function that is using curl:
void MainWindow::update_tb(){ CURL *curl; CURLcode res; std::string HTMLcontent; curl = curl_easy_init(); if(curl){ curl_easy_setopt(curl, CURLOPT_URL, "https://api.binance.com/api/v3/ticker/price"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeHTML); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &HTMLcontent); res = curl_easy_perform(curl); curl_easy_cleanup(curl); qDebug() << QString::fromStdString(HTMLcontent); } //qDebug() << QString::fromStdString(HTMLcontent); QSqlQuery query; std::string content = HTMLcontent; std::string pattern = "\\{\"symbol\":\"(.+?)\",\"price\":\"(.*?)\"\\}"; std::regex rule(pattern); std::smatch match; while(std::regex_search(content, match, rule)){ query.prepare("update coins_tb set VALUE='"+QString::fromStdString(match.str(2))+"' where TOKEN='"+QString::fromStdString(match.str(1))+"'"); if(!query.exec()){ QMessageBox::warning(this, "Erro", "Erro ao atualizar banco de dados"); } } int row = 0; query.prepare("select VALUE from coins_tb where TOKEN like'%"+ui->lineEdit_filter->text()+"%'"); if(!query.exec()){ }else{ query.first(); do{ ui->tw_tokens_list->setItem(row, 1, new QTableWidgetItem(query.value(0).toString())); row++; }while(query.next()); if(ui->tw_tokens_list->currentRow() > -1){ ui->label_value->setText(Global_var::token_value); } } }
function responsible for writing the HTML count in the variable:
size_t writeHTML(char* HTML_content, size_t char_size, size_t char_amount, char* buffer_in) { size_t bytes = char_size * char_amount; ((std::string*)buffer_in)->append((char*)HTML_content, bytes); return bytes; }
include and function prototype:
#include "mainwindow.h" #include "ui_mainwindow.h" #include "add_order.h" #include "Global_variables.h" #include "login.h" #include "wallet.h" #include <QDebug> #include "curl/curl.h" #include <regex> QString Global_var::current_token; QString Global_var::token_value; bool Global_var::login = false; size_t writeHTML(char* HTML_content, size_t char_size, size_t char_amount, char* buffer_in);
-
Use a debugger, see what's happening.
Also please don't post pictures but text. -
Use a debugger, see what's happening.
Also please don't post pictures but text.@Christian-Ehrlicher Debugg returns "" from HTMLcontent
-
@Christian-Ehrlicher Debugg returns "" from HTMLcontent
@hecker said in curl returning none of the HTML content:
Debugg returns "" from HTMLcontent
I said you should use a debugger, not print something out.
Make a breakpoint in your writeHTML()m function to see if it's called and what's going on in there.Don't know whjat this has to do with Qt though...