我正在尝试在在线服务器中进行身份验证,但我无法选择要下载的页面,这是我的代码:
获取请求:
QObject::connect(&access, SIGNAL(finished(QNetworkReply*)), &loop_get, SLOT(quit()));
url_str = QString("http://") + info + QString(".server.com");
server_url = QString("t") + info + QString("-") + info + QString(".server.com");
request.setUrl(QUrl(url_str));
reply = access.get(request);
loop_get.exec();
if(reply->error() != QNetworkReply::NoError)
{
throw std::runtime_error(reply->errorString().toStdString());
}
delete reply;
这里是发布请求,在获取请求完成后立即调用:
QObject::connect(&access, SIGNAL(finished(QNetworkReply*)), &loop_post, SLOT(quit()));
url_str = "/page_wanted?parameters=5&t=3";
//Assembly the message budy
msg_body = QString("message");
//assembly HTTP header
request.setUrl(QUrl(url_str));
request.setHeader(QNetworkRequest::ServerHeader, server_url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlenconded");
request.setHeader(QNetworkRequest::ContentLengthHeader, QString::number(message.size()));
reply = access.post(request, QByteArray(message.toStdString().c_str()));
loop_post.exec();
if(reply->error() == QNetworkReply::NoError)
{
qDebug() <<"that's ok:\n"<<reply->readAll();
}
else
{
qDebug() <<"That's not ok:\n"<<reply->errorString();
}
delete reply;
返回的错误是:
That's not ok:
"Protocol "" is unknown"
我不知道该怎么做,在谷歌上搜索我只找到了带我去那种方式的例子,所以如果有人可以帮助我会感谢你。:)