How to connect via API?
-
Still the same error or another one ?
-
Did you check whether you can connect to another https resource and if it triggers the same error ?
-
@Mikeeeeee you may try a JSON testing site with secure connections, like https://jsonplaceholder.typicode.com
i.e. https://jsonplaceholder.typicode.com/todos/1 will return:
{ "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false }
-
@Pablo-J.-Rogina said in How to connect via API?:
Tried to send to this address and got an old error.
-
And if you sent"http://json placeholder.typecode.com/todos/1" it works. Why https doesn't work?
-
Just to be sure add this to your code:
qDebug() << QSslSocket::supportsSsl(); qDebug() << QSslSocket::sslLibraryBuildVersionString(); qDebug() << QSslSocket::sslLibraryVersionString();
-
Are you sure you put the OpenSSL 1.0 dlls in the right folder ? Without mixing them with another version of OpenSSL.
-
hi
I wonder if it also wants libssl32.dll ? -
hey @Mikeeeeee,
You can try those .dll. I used it few weeks ago when I needed Qt SSL on Windows and it worked fine.
-
Thanks. https is working.
Trying to use the function TIME_SERIES_DAILY_ADJUSTED.
https://www.alphavantage.co/documentation/
If you do so it works:request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&outputsize=compact&apikey=XXXXXXXXXXXXX"));
If doing so does not work:
request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&outputsize=full&apikey=XXXXXXXXXXXXXXX"));
It's me doing something wrong or the server is not working?
[edit: removed API key SGaist]
-
Since you don't show how you are processing the QNetworkReply object created for your request one can only guess. What signals did you connect from the reply object ? What exactly do you mean by "does not work" ?
By the way, I've edited out your api key, it's not a good idea to post such information.
-
It's my h-file:
private slots: void on_testButton_clicked(); void testSlotFromQDebug(); void onReply(QNetworkReply* reply); private: Ui::MainWindow *ui; QNetworkAccessManager *apiQuery = new QNetworkAccessManager;
it's cpp-file:```
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);//connect(apiQuery, &QNetworkAccessManager::finished, this, &MainWindow::testSlotFromQDebug);
}
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_testButton_clicked()
{
QNetworkRequest request;
//request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&apikey=demo"));
request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&outputsize=full&apikey=111111"));
//request.setUrl(QUrl("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&outputsize=compact&apikey=1111"));QNetworkReply* reply = apiQuery->get(request); connect(reply ,&QNetworkReply::finished,this,std::bind(&MainWindow::onReply,this,reply ));
}
void MainWindow::testSlotFromQDebug()
{
//qDebug()<<"point1";
}void MainWindow::onReply(QNetworkReply* reply){
QJsonDocument jdoc = QJsonDocument::fromJson(reply->readAll());
//qDebug() << QSslSocket::supportsSsl();
//qDebug() << QSslSocket::sslLibraryBuildVersionString();
//qDebug() << QSslSocket::sslLibraryVersionString();
qDebug()<<jdoc;
// do something with the jdoc
} -
Again: what do you mean by "it's not working" when using the full output size ?