Results 1 to 3 of 3

Thread: QNetworkReply and https

  1. #1
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default QNetworkReply and https

    Hi, im using Qt 4.8.4 and i'm having problem sending through https protocol. Im having this code:

    Qt Code:
    1. int CardManager::postZipFile(QString cardNumber, QString bankerName, QString filename)
    2. {
    3. unsigned int r=0;
    4.  
    5. QNetworkAccessManager *manager = new QNetworkAccessManager();
    6.  
    7. QNetworkRequest request(QUrl(diagUrl.toUtf8()));
    8.  
    9. QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
    10.  
    11. QHttpPart chipCardSn;
    12. chipCardSn.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"chipcardsn\""));
    13. chipCardSn.setBody(cardNumber.toUtf8());
    14.  
    15. QHttpPart banker;
    16. banker.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; charset=iso-8859-2; name=\"banker\""));
    17. banker.setBody(bankerName.toUtf8());
    18.  
    19. QHttpPart fileName;
    20. fileName.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; charset=iso-8859-2; name=\"FileName\""));
    21. fileName.setBody(filename.toUtf8());
    22.  
    23. QHttpPart diagnostics;
    24. diagnostics.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"Diagnostics\""));
    25. diagnostics.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/x-zip-compressed"));
    26.  
    27. //load zip a convert to base64
    28. int length;
    29. char * buffer;
    30.  
    31. ifstream is;
    32. is.open ("/tmp/" + filename.toUtf8(), ios::binary );
    33.  
    34. // get length of file:
    35. is.seekg (0, ios::end);
    36. length = is.tellg();
    37. is.seekg (0, ios::beg);
    38.  
    39. // allocate memory:
    40. buffer = new char [length];
    41.  
    42. // read data as a block:
    43. is.read (buffer,length);
    44. is.close();
    45.  
    46. QByteArray array;
    47. for(int i=0; i<length; i++)
    48. {
    49. array[i] = buffer[i];
    50. }
    51.  
    52. array=array.toBase64();
    53. for(int i=56; i<array.length(); i+=57)
    54. {
    55. array.insert(i, "\n");
    56. }
    57.  
    58. diagnostics.setBody(array);
    59.  
    60. multipart->append(chipCardSn);
    61. multipart->append(banker);
    62. multipart->append(fileName);
    63. multipart->append(diagnostics);
    64.  
    65. QEventLoop loop;
    66. QNetworkReply *reply = manager->post(request, multipart);
    67. reply->ignoreSslErrors();
    68. connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    69.  
    70. QTimer timer;
    71. timer.singleShot(30000, &loop, SLOT(quit()));
    72. loop.exec();
    73.  
    74. if(reply->isFinished())
    75. {
    76. return 0;
    77. } else
    78. return 1;
    79. }
    80. }
    To copy to clipboard, switch view to plain text mode 

    When Im running this code with http address in diagUrl string, everything works fine. But when I try to send via https, reply is never finished and this function ends with timer timeout. Tried to connect reply's signal sslErrors to ingoreSslErrors slot, but getting Object::connect: No such signal QNetworkReplyImpl::sslErrors(QList<QSslError>). Any help with that? I really dont know what's wrong :/

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkReply and https

    Can you show the connect statement that didn't work?

    Are you sure you want to use HTTPS when you ignore SSL errors anyway?

    I am wondering that this works at all since you are sending headers in wrong encodings. Probably lucky and the strings only contain ASCII.

    Cheers,
    _

    P.S. have a look at QFile::readAll()

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QNetworkReply and https

    Make sure you do not have a firewall dropping your connection into a black hole.

Similar Threads

  1. Qt 4.7 Https?
    By MorrisLiang in forum Qt Programming
    Replies: 6
    Last Post: 3rd November 2010, 08:54
  2. QNetworkAccessManager and https. help!
    By valerino in forum Qt Programming
    Replies: 0
    Last Post: 22nd July 2010, 14:13
  3. QUrl and https
    By TomASS in forum Newbie
    Replies: 1
    Last Post: 15th March 2010, 22:49
  4. Https and windows
    By nicugh in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2009, 13:25
  5. Https POST Request
    By munna in forum Qt Programming
    Replies: 10
    Last Post: 11th November 2006, 14:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.