QUrl grief
-
wrote on 14 Sept 2013, 02:57 last edited by
I'm having some trouble with Qurls and QNetworkAccessManager::Get. Trouble is when I'm trying to get a complicated url like this: (ignore the spaces)
"http://10.0.0.1:60152/liveview.JPG?% 211234% 21http% 2dget% 3a% 2a% 3aimage% 2fjpeg% 3a% 2a% 21% 21% 21% 21% 21"
If I created the Qurl as:
@QUrl MyUrl("http://10.0.0.1:60152/liveview.JPG?% 211234% 21http% 2dget% 3a% 2a% 3aimage% 2fjpeg% 3a% 2a% 21% 21% 21% 21% 21"); @
When I use the get method qt changes all the % signs to % 25 so I'll get things like
@.JPG?% 25211234% 2521http...@
Which the server doesn't understand and the get fails.Using this code:
@QByteArray urltemp=QUrl::toPercentEncoding(IncomingUrl.toUtf8()); url=QUrl::fromEncoded(urltemp); ...->Get(url);@
Seems to have a correctly formatted url but the reply returns QNetworkReply::ProtocolUnknownError (301). If I put a simple URL through the above code it still looks correct, but I get the same error. Removing the above code and directly getting a simple url works.
How can I fix this error?
Edit: I am trying to show the urls with precent encoding. How do I post something with (percent sign)(Hex code) and not have the forum post look all messed up? For now I just put a space after each percent sign.
-
wrote on 14 Sept 2013, 08:04 last edited by
Hi,
I should use QUrlQuery class
@
QUrl url("http://my-url");QUrlQuery query;
query.addQueryItem("key","value");url.setQueryItem(query);
@Or you can also use a lot of other useful methods of the QUrlQuery class to create you url with arguments...
-
wrote on 16 Sept 2013, 02:02 last edited by
Found that sending ->Get the non percent encoded form works just fine.
@QByteArray UrlTemp(IncomingUrl.toUtf8()); IncomingUrl = QUrl::fromPercentEncoding(UrlTemp); QUrl url(IncomingUrl);@
Worked for me.
2/3