HTTP
-
Hi @Pranit-Patil
For HTTP in Qt there is QtNetwork module. for that you have to inlcude
QT += network in .pro file.after this you can add
#include <QtNetwork> in your file.Then you can use functionalities of QtNetwork.
Hierarchy of this is,
QNetworkRequest request(QUrl(“http://example.com/exampleapi”));
request.setHeader(QNetworkRequest::ContentTypeHeader, “application/xyz”);
QNetworkAccessManager nam;
QNetworkReply *reply = nam.post(request, QByteArray &data);
while(!reply->isFinished())
{
qApp->processEvents();
}
QByteArray response_data = reply->readAll();reply->deleteLater();
-
For set header you can,
- void QNetworkRequest::setRawHeader(const QByteArray & headerName, const QByteArray & headerValue);
Sets the value of the known header header to be value, overriding any previously set headers.
- void QNetworkRequest::setRawHeader(const QByteArray & headerName, const QByteArray & headerValue)
Sets the header headerName to be of value headerValue. If headerName corresponds to a known header (see QNetworkRequest::KnownHeaders), the raw format will be parsed and the corresponding "cooked" header will be set as well.
for example:
request.setRawHeader(QByteArray("Last-Modified"), QByteArray("Sun, 06 Nov 1994 08:49:37 GMT")); -
I am trying following code but not getting error like-
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_errorvoid MainWindow::on_pushButton_clicked()
{
QNetworkAccessManager * mgr = new QNetworkAccessManager(this); connect(mgr,SIGNAL(finished(QNetworkReply*)),this,SLOT(onfinish(QNetworkReply*)));
connect(mgr,SIGNAL(finished(QNetworkReply*)),mgr,SLOT(deleteLater()));QByteArray postData =(" user_token":{"Ej14qoqnm9PxZJWXXHPIzX8L2owzQuIPHA0QewilGs8fzScwp6XoPnsQ4KUb71iv","qr_code":"}");
QUrl serviceURL("https://dev.datoms.io/api/trade/initialization/create_device"); QNetworkRequest request(serviceURL);
request.setRawHeader("Post", "/api/trade/initialization/create_device HTTP/1.1"); request.setRawHeader("Host:", "dev.datoms.io");
request.setRawHeader("Cache-Control:","no-cache ");
mgr->post(request, postData);
}
void MainWindow::onfinish(QNetworkReply *rep)
{
QByteArray bts = rep->readAll();
ui->textBrowser->insertPlainText(bts);
} -
@Prince_0912 thanks for quick response .
i will try to implement -
@Prince_0912
simply i implement
in .cpp file
void MainWindow::on_pushButton_clicked()
{
QNetworkRequest request(QUrl("https://dev.datoms.io/api/trade/initialization/create_device"));//request.setHeader(QNetworkRequest::ContentTypeHeader, "application/xyz"); QNetworkAccessManager manager; QByteArray data =("user_token\":{\"Ej14qoqnm9PxZJWXXHPIzX8L2owzQuIPHA0QewilGs8fzScwp6XoPnsQ4KUb71iv\",\"qr_code\":\"QGt0Z9Q5J\",\"circuit_version\":\"1.0.0\",\"device_type\":1\"}"); QNetworkReply *reply = manager.post(request, data); while(!reply->isFinished()) { qApp->processEvents(); } QByteArray response_data = reply->readAll(); reply->deleteLater();
}
application Builded but not geeting any response from server
i got this errors
qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_CTX_new
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error -
Hi @Pranit-Patil ,
These error you can solve by this link .
OR
You can refer this link for implementing in another.
-
i m getting this type of issues-
qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_CTX_new
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
"Unable to init SSL Context:i already installed OpenSSL 1.0.2e (32bit) but again same problem faced
anyone knows help meThank You.
-
At last, I found the solution. click on following link and download latest version of Win32 OpenSSL v1.1.0h note:Dont download light version ,download 30 MB file
http://slproweb.com/products/Win32OpenSSL.html
after installing OpenSSL opy the following three dll's in the the directory containing your binary file/Debug folder where your .exe file present.
- libeay32.dll
- libssl32.dll
- ssleay32.dll
I solved my problem this one
-
Ok finally you got solution. Now make this Topic to Mark as Solved.
Go to right hand side of page -> click on Topic Tools -> Mark as Solved.
Thank you. -
@Prince_0912 Thank you for your guidlines