0

I'm trying to use this http://www.rcsb.org/pdb/software/rest.do REST services with Qt. I did some get requests with no problem, but when I try to do a post request to its advanced search(which is an XML web service), I get no response.

This is the post request I'm trying:

<orgPdbQuery>

<queryType>org.pdb.query.simple.StructureIdQuery</queryType>

<description>Simple query for a list of PDB IDs (1 IDs) : 3I5F</description>

<structureIdList>3I5F</structureIdList>

</orgPdbQuery>

And this is my code for the request:

void WindowWrapper::postRequest()
{
    QNetworkRequest request;

    QUrl res = QUrl(request_url_);

    QUrl query;
    query.addQueryItem("queryType","org.pdb.query.simple.StructureIdQuery");
    query.addQueryItem("structureIdList","3I5F");

    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream");
    request.setUrl(res);

    QObject::connect(network_, SIGNAL(finished(QNetworkReply*)),
                     this, SLOT(slotRequestFinished(QNetworkReply*)));

    network_->post(request, query.encodedQuery());
}


void WindowWrapper::slotRequestFinished(QNetworkReply* reply)
{
    if(reply->error() > 0)
    {
        qDebug() << reply->errorString();
    }
    else
    {
        QByteArray data = reply->readAll();            

        qDebug() << "Request successful!";
        qDebug() << data;             
    }
}

And the method call:

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

And on my debug output I get this:

Request successful! 
"" 

Edit:

I also tried this for the request, but I still got no response:

void WindowWrapper::postRequest()
{
    QNetworkRequest request;

    request.setRawHeader("Content-Type", "text/xml;charset=UTF-8");
    request.setUrl(QUrl(request_url_));

    QString query =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
        "<orgPdbQuery>"
        "<queryType>org.pdb.query.simple.StructureIdQuery</queryType>"
        "<description>Simple query for a list of PDB IDs (1 IDs) : 3I5F</description>"
        "<structureIdList>3I5F</structureIdList>"
        "</orgPdbQuery>";

    QObject::connect(network_, SIGNAL(finished(QNetworkReply*)),
                 this, SLOT(slotRequestFinished(QNetworkReply*)));

    network_->post(request, query.toUtf8());

}

Anyone knows what am I doing wrong? Please...

userX731
  • 43
  • 2
  • 6

2 Answers2

1

The link you gave says the query data has to be encoded in XML.

And I don't know why, but the service seems to only allow application/x-www-form-urlencoded as Content-Type, all other types trigger a redirection to the 'rest.do' page.

Community
  • 1
  • 1
alexisdm
  • 29,448
  • 6
  • 64
  • 99
  • 0 down vote You're right, I forgot to add that the advanced search from that page is an XML web service but I have no idea how to make a POST request to a XML/SOAP service – userX731 Mar 24 '12 at 03:22
  • Yeah you are right, thank you!, with application/x-www-form-urlencode as Content-Type i get a response. – userX731 Mar 24 '12 at 23:06
0

I dont think that you are sending data in right way. You are trying to create request by following code, which will not send xml request to server.

QUrl query;
    query.addQueryItem("queryType","org.pdb.query.simple.StructureIdQuery");
    query.addQueryItem("structureIdList","3I5F");

you need to do something like following to send xml data to server.

QNetworkRequest request(QUrl("https://graph.facebook.com/me/feed");
mCurrentRequest  = mNetManager.post(request,postData.toAscii());
connect(mCurrentRequest,SIGNAL(finished()),this,SLOT(messageResponse()));

Here in above code postData should be your xml request. you can refer this link for more info.

Kunal
  • 3,475
  • 21
  • 14