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:
Qt Code:
  1. var https = new XMLHttpRequest();
  2. https.open("POST", url, true);
  3.  
  4. https.setRequestHeader("Content-type", "application/json");
  5. https.onreadystatechange = function() {
  6. if (https.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
  7. var status = https.status;
  8. if(status != 200) {
  9. app.logWrite("HttpsPostToService; Headers received; Error. Status: " + status + ". Status text: " + https.statusText, 4);
  10. return;
  11. }
  12. } else if (https.readyState == XMLHttpRequest.DONE) {
  13. var status = https.status;
  14. if(status != 200) {
  15. app.logWrite("HttpsPostToService; Done; Not OK. Status: " + status + ". Status text: " + https.statusText, 4);
  16. return;
  17. }
  18. var data = null;
  19. data = https.responseText;
  20. app.logWrite("HttpsPostToService; Done; OK. Received following data:", 4);
  21. app.logWrite("HttpsPostToService; " + data, 4);
  22. }
  23. }
  24. 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.


Qt Code:
  1. if (QFile::exists("C:/Data/Certs/certificate.cer"))
  2. {
  3. QFile certFile("C:/Data/Certs/certificate.cer");
  4. if (certFile.open(QIODevice::ReadOnly))
  5. {
  6. QSslCertificate cert(&certFile, QSsl::Der);
  7. if (! cert.isNull())
  8. {
  9. qDebug() << "Cert not null";
  10. if (cert.isValid())
  11. {
  12. qDebug() << "Cert is valid";
  13. QSslSocket::addDefaultCaCertificate(cert);
  14. qDebug() << "Cert was added. Info: " << cert.serialNumber();
  15. }
  16. else
  17. {
  18. qDebug() << "Cert is NOT valid";
  19. }
  20.  
  21.  
  22. }
  23. else
  24. {
  25. qDebug() << "Cert is null";
  26. }
  27. if (certFile.isOpen())
  28. certFile.close();
  29. }
  30. }
  31.  
  32.  
  33. qDebug() << "Root CA certificates: \n" << QSslSocket::defaultCaCertificates();
To copy to clipboard, switch view to plain text mode