7

I want to be able to read the headers sent back from a webpage in SSL mode. My Qt app however can't reach the webpage because it's in SSL mode I am gathering? Normal webview browsing in SSL is possible in my app using this connect:

connect(view->page()->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError> & )),
                        this, SLOT(onSslErrors(QNetworkReply*, const QList<QSslError> & )));

This suppresses the SSL errors in the webview but I have a separate function which get's the headers using this method:

//Send a request to validate URL
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkRequest request;
request.setUrl(QUrl(text));
request.setRawHeader("User-Agent", "MyApp1.0");
request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
                  QNetworkReply *reply = manager->get(request);
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();

qDebug() << "QLoop: " << reply->rawHeader("My-Application");
  if(reply->rawHeader("My-Application") == "1"){
      appUrl = text;
  }

I need this method because I set a config file with our webapps URL in it before the the app will connect to it using webview->load(QURL(appUrl )). Just not sure how to supress/handle SSL errors using QNetworkAccessManager?

Kal
  • 2,239
  • 6
  • 36
  • 74

1 Answers1

9

You need to connect your QNAM objects signal sslErrors(QNetworkReply *, QList<QSslError>) to a slot where you set QNetworkReply::ignoreSslErrors() and that'll allow QNAM to continue running. Qt Docs on it.

Nicholas Smith
  • 11,642
  • 6
  • 37
  • 55
  • Thanks very much, I tried `reply->ignoreSslErrors();` in the middle somewhere lol and it didn't work so I'll give your method a go :) – Kal Jan 11 '13 at 12:10
  • No bother, first time I tried it I completely ignored that the signal was being emitted and put `reply->ignoreSslErrors()` where I created QNAM. Simple mistake! – Nicholas Smith Jan 11 '13 at 12:14
  • Only thing I am finding is `SIGNAL(sslErrors(QNetworkReply*, const QList & )), SLOT(onSslErrors(QNetworkReply*, const QList & )));` sometimes get's fired sometimes doesn't? Maybe I am implimenting it wrong? This is my first Qt application lol - @Nicholas Smith – Kal Jan 11 '13 at 12:53