qt ssl and https



  • I'm getting network error 301 when reading a text file from an https website. I copied ssleay32.dll and libelay32.dll alongside my exe and added CONFIG += openssl-linked into my project file. My Qt is 5.10.1, statically linked. Works fine with a http website of course.

    Most of what I read seemed to suggest that the two dlls and the openssl-linked flag would be all that's required. Are there additional steps I need to take?


  • Lifetime Qt Champion

    Hi,

    What version of OpenSSL are you using ?
    For what architecture ?
    With which compiler ?



  • 1.0.2.o, March 2018
    mingw32
    Windows 10
    Qt 5.10.1


  • Lifetime Qt Champion

    Might be a silly question but did you check that the build is for the correct architecture ?



  • @Jedd said in qt ssl and https:

    I'm getting network error 301

    Do you mean HTTP error 301? If so, you may want to check the reasons and how to solve it by searching the net i.e. this article may help.



  • That's very odd, since this is a Windows-only error. It does not occur with Linux or Mac.

    My code for reading the text file:

    QNetworkRequest request;
    request.setUrl(QUrl("https://www.mysite.com/file.txt"));
    QNetworkAccessManager *m_networkManager = new QNetworkAccessManager();
    QNetworkReply *reply = m_networkManager->get(request);
    
    connect(reply, SIGNAL(finished()),
            this, SLOT(onRequestCompleted()));
    

    the error code returns 301 for Windows only, not Linux, not Mac.

       int err = reply->error();
       QString s2 = QString::number(err);
    

    Additionally, I recompiled 5.10.1 using thus:

    configure.bat -opensource -confirm-license -release -static -opengl desktop -platform win32-g++ -prefix "C:\Qt\5.10.1_Static" -skip webengine -openssl-linked -I C:/OpenSSL-Win32/include -L C:/OpenSSL-Win32/lib/MinGW OPENSSL_LIBS="-llibeay32 -lssleay32" -nomake tools -nomake tests -nomake examples

    And no error with this kit, as long as I have the OpenSSL eay dll files included AND I have msvcr120.dll
    (this is a real irritant, since it's not usually required for mingw32!)



  • @SGaist

    @SGaist said in qt ssl and https:

    Might be a silly question but did you check that the build is for the correct architecture ?

    I'm not sure I understand. Windows mingw32. Everything seems fine with the exception of this ssl issue.



  • @Jedd if the exact Qt application runs Ok under Linux/Mac but is getting HTTP status code 301 contacting the exact same server, I'd say it's a perfect case to do network traffic analysis with Wireshark. You may want to compare what the Qt application is sending and receiving both under Windows (faulty) and Linux (Ok).
    In addition, this stack overflow question may help you.



  • @Pablo-J.-Rogina As I mentioned, the Windows error goes away with Qt recompiled statically with -ssl-linked. The only issue with this solution is the msvcr120.dll requirement, which is not a good thing. I've never required it before for a mingw32-compiled program.



  • @Jedd said in qt ssl and https:

    I've never required it before for a mingw32-compiled program.

    Using the same environment as you're using now?
    I mean, you are now using "with Qt recompiled statically with -ssl-linked"


  • Lifetime Qt Champion

    You can use something like Dependency Walker to check where that dependency comes from.



  • @Pablo-J.-Rogina Yes. I've never used VS on Windows, just mingw. In fact, VS isn't even installed.



  • @SGaist Thanks for that suggestion. Depends revealed the openssl I'm includiing has an msvcr dependency. I'm looking for a different solution. Pity I can't just include the openssl DLLs that Qt uses.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.