Hi all,
I'm developing an app for Symbian S60 5th and Sym^3 phones using Nokia Qt SDK v.1.1.3.
My app needs to communicate with a server through HTTPS Post. The server has a certificate (.cer file) to be used for verification and encryption.
I'm trying to implement the network communication in QML/JS using XmlHttpRequest but it does not work: it is interrupted during handshake with readystate = DONE but with status = 0 and status text = 0.
My code is:
var https = new XMLHttpRequest();
https.open("POST", url, true);
https.setRequestHeader("Content-type", "application/json");
https.onreadystatechange = function() {
if (https.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
var status = https.status;
if(status != 200) {
app.logWrite("HttpsPostToService; Headers received; Error. Status: " + status + ". Status text: " + https.statusText, 4);
return;
}
} else if (https.readyState == XMLHttpRequest.DONE) {
var status = https.status;
if(status != 200) {
app.logWrite("HttpsPostToService; Done; Not OK. Status: " + status + ". Status text: " + https.statusText, 4);
return;
}
var data = null;
data = https.responseText;
app.logWrite("HttpsPostToService; Done; OK. Received following data:", 4);
app.logWrite("HttpsPostToService; " + data, 4);
}
}
https.send(jsonpar);
var https = new XMLHttpRequest();
https.open("POST", url, true);
https.setRequestHeader("Content-type", "application/json");
https.onreadystatechange = function() {
if (https.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
var status = https.status;
if(status != 200) {
app.logWrite("HttpsPostToService; Headers received; Error. Status: " + status + ". Status text: " + https.statusText, 4);
return;
}
} else if (https.readyState == XMLHttpRequest.DONE) {
var status = https.status;
if(status != 200) {
app.logWrite("HttpsPostToService; Done; Not OK. Status: " + status + ". Status text: " + https.statusText, 4);
return;
}
var data = null;
data = https.responseText;
app.logWrite("HttpsPostToService; Done; OK. Received following data:", 4);
app.logWrite("HttpsPostToService; " + data, 4);
}
}
https.send(jsonpar);
To copy to clipboard, switch view to plain text mode
I tried successfully to load server certificate among the default CA Certificates for QSSLSockets but this does not solve the problem (see code below).
I was thinking QML to use QSSLSocket in SSL communication but perhaps I'm wrong.
My question is: is it possible to manage SSL with XMLHttpRequest? If yes how can I add the certificate in order to use it?
Or have I to go with a Qt implementation?
Thanks in advance for any support.
if (QFile::exists("C:/Data/Certs/certificate.cer")) {
QFile certFile
("C:/Data/Certs/certificate.cer");
{
QSslCertificate cert(&certFile, QSsl::Der);
if (! cert.isNull())
{
qDebug() << "Cert not null";
if (cert.isValid())
{
qDebug() << "Cert is valid";
QSslSocket::addDefaultCaCertificate(cert);
qDebug() << "Cert was added. Info: " << cert.serialNumber();
}
else
{
qDebug() << "Cert is NOT valid";
}
}
else
{
qDebug() << "Cert is null";
}
if (certFile.isOpen())
certFile.close();
}
}
qDebug() << "Root CA certificates: \n" << QSslSocket::defaultCaCertificates();
if (QFile::exists("C:/Data/Certs/certificate.cer"))
{
QFile certFile("C:/Data/Certs/certificate.cer");
if (certFile.open(QIODevice::ReadOnly))
{
QSslCertificate cert(&certFile, QSsl::Der);
if (! cert.isNull())
{
qDebug() << "Cert not null";
if (cert.isValid())
{
qDebug() << "Cert is valid";
QSslSocket::addDefaultCaCertificate(cert);
qDebug() << "Cert was added. Info: " << cert.serialNumber();
}
else
{
qDebug() << "Cert is NOT valid";
}
}
else
{
qDebug() << "Cert is null";
}
if (certFile.isOpen())
certFile.close();
}
}
qDebug() << "Root CA certificates: \n" << QSslSocket::defaultCaCertificates();
To copy to clipboard, switch view to plain text mode
Bookmarks