1

i'm trying to authenticate in a online server, but i can't select the page that i want to download, here is my code:

The Get request:

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;

here the post request, is called right after the get request finish:

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;

the error returned is:

That's not ok:
"Protocol "" is unknown"

i don't know how to do that, searching on google i only found examples that takes me to that way, so if someone could help i'll thank you. :)

László Papp
  • 51,870
  • 39
  • 111
  • 135
user2542813
  • 323
  • 3
  • 12

2 Answers2

0

The line

url_str = "/page_wanted?parameters=5&t=3";

is missing a plus sign :D try

url_str += "/page_wanted?parameters=5&t=3";

and you should be good to go...

Massa
  • 8,647
  • 2
  • 25
  • 26
  • yeah, i've did that and now it got no errors, but now i have no data to read, here is the result: that's ok: "" – user2542813 Apr 08 '14 at 23:45
  • what is the result of `curl -D- http://$INFO.server.com/page_wanted?parameters=5&t3` (where `$INFO` is the value of the `info` string in your program?? and `curl -D- --data /tmp/data http://$INFO.server.com/page_wanted?parameters=5&t3`, putting the contents of `message` in `/tmp/data`? – Massa Apr 09 '14 at 10:52
0

The following error message should be comprehensive:

"Protocol "" is unknown"

This means the qtnetwork module that you are trying to use has not found a protocol in the request URL, i.e. "http", "ftp", and so on.

That should give a hint that you forget to send that for some reason. Failing that, you have sent an unknown. If you take a look at your URL construction code, you can see that you miss the protocol and network location from there because you override that with the suburl rather than appending. This is the line I am referring to:

url_str = "/page_wanted?parameters=5&t=3";

The right fix would to override the existing protocol name and network location rather than overriding. Thereby, you would be writing something like this:

url_str.append("/page_wanted?parameters=5&t=3");

This is one typical use case when using the comprehensive named methods can avoid the probably unintentional typo between = and +=.

László Papp
  • 51,870
  • 39
  • 111
  • 135