June 19, 2012

xvision xvision
Lab Rat
3 posts

[SOLVED] content-type missing in HTTP POST, defaulting to application/octet-stream

 

Just upgraded QT to latest version 4.8.1 libraries on Linux Ubuntu box 10.04 from version 4.7.X.

With the new version I am receiving an error from our server.
QT provides the following warning message:

  1. content-type missing in HTTP POST, defaulting to application/octet-stream

Our server wont accept the posted data. This ran fine with previous release.
I am aware that the default ContentTypeHeader type needs to be explicitly set under version 4.8.
However even when adding in the setHeader code shown below, I still receive the same error.

Any ideas? Do I also need to set the contentHeader length field too or is this handled automatically.

  1.  QNetworkRequest request;
  2.     QUrl params;
  3.     params.addQueryItem("version","1.0");
  4.     params.addQueryItem("siteid","12345");
  5.     params.addQueryItem("recordid","12345");                  
  6.    
  7.     request.setUrl(serverUrl);
  8.  
  9.     request.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/x-www-form-urlencoded"));
  10.     //request.setHeader(QNetworkRequest::ContentLengthHeader,params.encodedQuery().length());
  11.  
  12.     nam->post(QNetworkRequest(serverUrl),params.encodedQuery());
  13.    

3 replies

June 20, 2012

AcerExtensa AcerExtensa
Robot Herder
567 posts

contentHeader length is set automatically.

Sure it wouldn’t work. You set headers for request instance but don’t use this instance in post request!?

This:

  1. nam->post(QNetworkRequest(serverUrl),params.encodedQuery());

should look like this:

  1. nam->post(request,params.encodedQuery());

 Signature 

God is Real unless explicitly declared as Integer.

June 20, 2012

xvision xvision
Lab Rat
3 posts

Thanks AcerExtensa. Need to cut back on the coffee. That worked as expected..

June 20, 2012

AcerExtensa AcerExtensa
Robot Herder
567 posts

Glad I could help you. Please add “[SOLVED]” to the left of the topic subject.

 Signature 

God is Real unless explicitly declared as Integer.

 
  ‹‹ QTextEdit and EditEvent      Removing red underlines in code ››

You must log in to post a reply. Not a member yet? Register here!