QT: I was wondering if there is a way to create a QUrl or another URL class object from string without encoding the final URL. For example, here is a snippet of my code:
QString GetJsonStringFromURL(QString url) //url == "192.168.0.111/controller?POSITION|03|100"
{
QEventLoop eventLoop;
QNetworkAccessManager mgr;
QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
QNetworkRequest req( QUrl::fromUserInput(url) ) ;
QNetworkReply *reply = mgr.get(req);
eventLoop.exec(); //wait till reply finished
QString strReply = reply->readAll();
return strReply;
}
This code accesses a local area network controller requesting it's json with a get method, while passing a parameter in the url. The url i'm passing gets percent encoded to:
"192.168.0.111/controller?POSITION%7C03%7C100"
which i am trying to avoid. The server i'm trying to access is a custom piece of hardware with firmware written in C which doesn't incorporate percent decoding. I would like to avoid doing maintenance on the server side. I have tried going through QUrl class reference but none of the available methods provided the wanted result.
This is not possible with QNetworkRequest
since each request requires a QUrl object that does store the destination and is internally converted into an encoded string.
setRawHeader does not work for you, since it can set all HTTP headers except from the URL, that is part of the GET request.
Confirm raw HTTP header format curl -v http://stackoverflow.com/questions/
GET /questions/ HTTP/1.1
User-Agent: curl/7.37.1
Host: stackoverflow.com
Accept: */*
Thus you need an entirely raw socket connection (which I have no experience with).