[Interest] QHttp post with headers

Viktor Engelmann viktor.engelmann at qt.io
Mon Aug 22 11:11:25 CEST 2016


We are currently working on that for WebEngine.
See https://codereview.qt-project.org/#/c/167422/


On 13.07.2016 09:27, Reinhardt Behm wrote:
> On Friday 20 May 2016 15:27:27 Eric Laffoon wrote:
>> > Hi all,
>> > 
>> > It's a little emberassing but I'm still using some Qt3 software. Kommander
>> > is partially ported to Qt4 and I've been running my business with it since
>> > 2007. I'm rebuilding my biz and hope to have more time in the future. I was
>> > writing parser code a few years back but I'm really rusty now with C++.
>> > 
>> > I need to be able to post data and I need to be able to send a custom header
>> > which includes the user key as a header. It's very important and it looked
>> > easy but I've been coding late at night several days with no joy.
>> > 
>> > Can anyone recommend some Qt3 or Qt4 code that uses QHttp and associated
>> > network classes to post with additional header data? I've managed to get
>> > QHttp::post( const QString & path, const QByteArray & data, QIODevice * to =
>> > 0 ) to work but it looks like I need to use the request function instead.
>> > 
>> > This is the post function.
>> > 
>> > 
>> > int Http::httpPost()
>> > {
>> >   m_data = "";
>> >   QString hdr;
>> >   QString str;
>> >   QByteArray arData;
>> >   QHttpResponseHeader header;
>> > 
>> >   for (QMapConstIterator<QString, QString> it = m_headers.begin(); it !=
>> > m_headers.end(); it++)
>> >     hdr += QString("%1 : %2\r\n").arg(it.key()).arg(it.data());
>> >   hdr += ""; //"\r\n";
>> > 
>> >   header = QHttpRequestHeader::QHttpRequestHeader(const hdr&);
>> > 
>> >   for (QMapConstIterator<QString, QString> it = m_values.begin(); it !=
>> > m_values.end(); it++)
>> >     str += QString("%1%2=%3").arg(it != m_values.begin() ? "&" : "")
>> >         .arg(it.key()).arg(it.data());
>> > 
>> >   arData.duplicate(static_cast<const char *>(str), str.length());
>> >   job->request(header&, arData&, 0);
>> > 
>> >   return 1; //not used
>> > }
>> > 
>> > QString Http::httpShowValues()
>> > {
>> >  QString str;
>> >  for (QMapConstIterator<QString, QString> it = m_values.begin(); it !=
>> > m_values.end(); it++)
>> >  {
>> >     str += QString("%1\t%2%3") .arg(it.key()).arg(it.data()).arg(it !=
>> > m_values.end() ? "\n" : "");
>> >  }
>> >  return str;
>> > }
>> > 
>> > 
>> > This is my current make error
>> > 
>> > ../../src/http.cpp: In member function 'int Http::httpPost()':
>> > ../../src/http.cpp:136:51: error: expected primary-expression before 'const'
>> > header = QHttpRequestHeader::QHttpRequestHeader(const hdr&);
>> >                                                    ^
>> > ../../src/http.cpp:136:61: error: cannot call constructor
>> > 'QHttpRequestHeader::QHttpRequestHeader' directly [-fpermissive]
>> >    header = QHttpRequestHeader::QHttpRequestHeader(const hdr&);
>> >                                                              ^
>> > ../../src/http.cpp:136:61: error:   for a function-style cast, remove the
>> > redundant '::QHttpRequestHeader' [-fpermissive]
>> > 
>> > Yes, I know I have a constructor in there, but QHttpHeader::setValue is pure
>> > virtual. I can't remember how to inherit that and use it in a QHttp object.
>> > 
>> > I don't really have a week to brush up on C++. Just need to see how to
>> > construct a request with headers and data.
>> > 
> Eric,
> I was in the same situation some time ago. The original program was done 
> during Qt3.3 times and I had to port it to Qt5. Nearly all HTTP server stuff 
> is gone. I ended up, doing it myself. It isn't that hard.
> If you give me until next week, I can extract the relevant parts (more or less 
> 3 classes) and give it to you.

-- 


Viktor Engelmann
Software Engineer

The Qt Company GmbH
Rudower Chaussee 13
D-12489 Berlin
Viktor.Engelmann at qt.io
+49 151 26784521
http://qt.io

Geschäftsführer: Mika Pälsi, Juha Varelius, Mika Harjuaho
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht
Charlottenburg, HRB 144331 B
<http://qt.io>
<http://www.facebook.com/Qt> 	<http://www.twitter.com/qtproject>
<https://www.linkedin.com/company/the-qt-company/>
<https://plus.google.com/104580575722059274792>
<https://www.youtube.com/QtStudios>

Qt World Summit 2016 <http://qtworldsummit.com/>
Qt World Summit 2016 | Pier 27, San Francisco, CA
Experience Exponential Potential on October 18-20
www.qtworldsummit.com <http://www.qtworldsummit.com>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160822/e71d0e0b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_logo_with_text_green_rgb_400x141.png
Type: image/png
Size: 16849 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160822/e71d0e0b/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_facebook.png
Type: image/png
Size: 1407 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160822/e71d0e0b/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_twitter.png
Type: image/png
Size: 1778 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160822/e71d0e0b/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_linkedin.png
Type: image/png
Size: 1532 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160822/e71d0e0b/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_googleplus.png
Type: image/png
Size: 1957 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160822/e71d0e0b/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_youtube.png
Type: image/png
Size: 1610 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160822/e71d0e0b/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qtworldsummit2016_banner.jpg
Type: image/jpeg
Size: 35183 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160822/e71d0e0b/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: viktor_engelmann.vcf
Type: text/x-vcard
Size: 271 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160822/e71d0e0b/attachment.vcf>


More information about the Interest mailing list