[Interest] QHttp post with headers

Eric Laffoon sequitur at kdewebdev.org
Sat May 21 00:27:55 CEST 2016


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.

Thanks

Eric Laffoon
.



More information about the Interest mailing list