Qt Web 服务发布查询 [英] Qt Web Service post query
问题描述
我正在尝试使用这个 http://www.rcsb.org/pdb/software/rest.do 使用 Qt 的 REST 服务.我做了一些没有问题的获取请求,但是当我尝试对其高级搜索(这是一个 XML Web 服务)执行发布请求时,我没有得到任何响应.
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>
这是我的请求代码:
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;
}
}
和方法调用:
wrapper_->set_request_url("http://www.rcsb.org/pdb/rest/search/");
wrapper_->postRequest();
在我的调试输出中,我得到了这个:
And on my debug output I get this:
Request successful!
""
我也尝试过这个请求,但我仍然没有得到回应:
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...
推荐答案
您提供的链接说查询数据必须以 XML 编码.
The link you gave says the query data has to be encoded in XML.
我不知道为什么,但该服务似乎只允许 application/x-www-form-urlencoded
作为 Content-Type
,所有其他类型触发重定向到rest.do"页面.
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.
这篇关于Qt Web 服务发布查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!