March 24, 2012

mugen731 mugen731
Lab Rat
1 posts

Qt- Web service Requests

 

I’m trying out web service requests using this site as an example:
http://www.rcsb.org/pdb/software/rest.do

I got some GET REST request to work, but I’ have no idea how to send the XML POST for its advanced search service. This is what I tried:

  1. void WindowWrapper::postRequest()
  2. {
  3.     QNetworkRequest request;
  4.  
  5.     request.setRawHeader("Content-Type", "text/xml;charset=UTF-8");
  6.     request.setUrl(QUrl(request_url_));
  7.  
  8.     QString query =
  9.             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  10.             "<orgPdbQuery>"
  11.             "<queryType>org.pdb.query.simple.StructureIdQuery</queryType>"
  12.             "<description>Simple query for a list of PDB IDs (1 IDs) : 3I5F</description>"
  13.             "<structureIdList>3I5F</structureIdList>"
  14.             "</orgPdbQuery>";
  15.  
  16.     QObject::connect(network_, SIGNAL(finished(QNetworkReply*)),
  17.                      this, SLOT(slotRequestFinished(QNetworkReply*)));
  18.  
  19.     network_->post(request, query.toUtf8());
  20.  
  21. }
  22.  
  23.  
  24. void WindowWrapper::slotRequestFinished(QNetworkReply* reply)
  25. {
  26.     if(reply->error() > 0)
  27.     {
  28.         qDebug() << reply->errorString();
  29.     }
  30.     else
  31.     {
  32.         QByteArray data = reply->readAll();            
  33.  
  34.         qDebug() << "Request successful!";
  35.         qDebug() << data;            
  36.     }
  37. }

And this is how i call the method:

  1. wrapper_->set_request_url("http://www.rcsb.org/pdb/rest/search/");
  2.  
  3. wrapper_->postRequest();

There’s no error on the request, but i get no response at all…

Does anyone know how can i do this?

1 reply

March 25, 2012

mugen731 mugen731
Lab Rat
1 posts

It seem that the service from that site only accepts application/x-www-form-urlencoded as Content-Type. Now it’s working..

 
  ‹‹ Sharing some code with community      OpenGL and frame drop ››

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