QUrl setPath with the symbol '?'
-
Hi.
When I use setPath("/Streaming/channels/1/picture?snapShotImageType=JPEG"), the output is aQUrl("http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG")
Symbol was replaced
? -> %3FI do not need it. I tried using QUrl::ParsingMode, but it did not help.
How to leave this character? -
Hi.
When I use setPath("/Streaming/channels/1/picture?snapShotImageType=JPEG"), the output is aQUrl("http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG")
Symbol was replaced
? -> %3FI do not need it. I tried using QUrl::ParsingMode, but it did not help.
How to leave this character?I think it should be that way. Check out this and the corrsponding rfc , because it is the way as sent.
In case you want to change it you can use QString::replace
-
I think it should be that way. Check out this and the corrsponding rfc , because it is the way as sent.
In case you want to change it you can use QString::replace
@koahnig thanks, it's useful article.
I have not found how to disable the conversion of characters, so I decided to create an address by QString. -
Hi @Alexorleon,
The
%3F
sequence was not replaced during parsing, but during presentation.Consider:
QUrl url1(QLatin1Literal("http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG")); qDebug() << url1.path(); qDebug() << url1.path(QUrl::FullyEncoded); qDebug() << url1.query(); QUrl url2(QLatin1Literal("http://admin@192.168.1.64/Streaming/channels/1/picture?snapShotImageType=JPEG")); qDebug() << url2.path(); qDebug() << url2.path(QUrl::FullyEncoded); qDebug() << url2.query();
The output is:
"/Streaming/channels/1/picture?snapShotImageType=JPEG" "/Streaming/channels/1/picture%3FsnapShotImageType=JPEG" "" "/Streaming/channels/1/picture" "/Streaming/channels/1/picture" "snapShotImageType=JPEG"
Which is exactly what I'd expect (given that the default argument to QUrl::path is
QUrl::FullyDecoded
).Edit:
Just adding an example that's a little closer to your original post:
QUrl url("http://admin@192.168.1.64"); url.setPath("/Streaming/channels/1/picture?snapShotImageType=JPEG"); qDebug() << url.toString(QUrl::FullyEncoded);
Output:
"http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG"
Cheers.
-
Hi @Alexorleon,
The
%3F
sequence was not replaced during parsing, but during presentation.Consider:
QUrl url1(QLatin1Literal("http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG")); qDebug() << url1.path(); qDebug() << url1.path(QUrl::FullyEncoded); qDebug() << url1.query(); QUrl url2(QLatin1Literal("http://admin@192.168.1.64/Streaming/channels/1/picture?snapShotImageType=JPEG")); qDebug() << url2.path(); qDebug() << url2.path(QUrl::FullyEncoded); qDebug() << url2.query();
The output is:
"/Streaming/channels/1/picture?snapShotImageType=JPEG" "/Streaming/channels/1/picture%3FsnapShotImageType=JPEG" "" "/Streaming/channels/1/picture" "/Streaming/channels/1/picture" "snapShotImageType=JPEG"
Which is exactly what I'd expect (given that the default argument to QUrl::path is
QUrl::FullyDecoded
).Edit:
Just adding an example that's a little closer to your original post:
QUrl url("http://admin@192.168.1.64"); url.setPath("/Streaming/channels/1/picture?snapShotImageType=JPEG"); qDebug() << url.toString(QUrl::FullyEncoded);
Output:
"http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG"
Cheers.
@Paul-Colby
"http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG" this is address of the IP-camera. It does not work with %3F.
And if I use setPath, it changes the value automatically.I do this so:
QString strUrl("http://admin@192.168.1.64/Streaming/channels/1/picture?snapShotImageType=JPEG"); QUrl url(strUrl);
Output:
QUrl("http://admin@192.168.1.64/Streaming/channels/1/picture?snapShotImageType=JPEG")
It is right for me.
-
@Paul-Colby
"http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG" this is address of the IP-camera. It does not work with %3F.
And if I use setPath, it changes the value automatically.I do this so:
QString strUrl("http://admin@192.168.1.64/Streaming/channels/1/picture?snapShotImageType=JPEG"); QUrl url(strUrl);
Output:
QUrl("http://admin@192.168.1.64/Streaming/channels/1/picture?snapShotImageType=JPEG")
It is right for me.
@Alexorleon said in QUrl setPath with the symbol '?':
http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG" this is address of the IP-camera. It does not work with %3F.
Who, or what, tells you that's the "address of the IP-camera"?
Typically web-based APIs would use a
?
there, not%3F
, since most API servers would be sending all requests to the same*/picture
endpoint, then passing the image type as an optional query parameter to that endpoint. This is convention only, the standards don't require it. But it does suggest that whoever / whatever told you that the URL contains a%3F
was mistaken. Perhaps some poorly-translated-to-English manual?Indeed, it appears (just based on the URL format) that you are using a Hikvision device, and those, the
snapShotImageType
is a query parameter, so should be preceded by a?
or&
, according to their user manuals (such as this one). So I think you have your input URL wrong to begin with.Cheers.
-
@Alexorleon said in QUrl setPath with the symbol '?':
http://admin@192.168.1.64/Streaming/channels/1/picture%3FsnapShotImageType=JPEG" this is address of the IP-camera. It does not work with %3F.
Who, or what, tells you that's the "address of the IP-camera"?
Typically web-based APIs would use a
?
there, not%3F
, since most API servers would be sending all requests to the same*/picture
endpoint, then passing the image type as an optional query parameter to that endpoint. This is convention only, the standards don't require it. But it does suggest that whoever / whatever told you that the URL contains a%3F
was mistaken. Perhaps some poorly-translated-to-English manual?Indeed, it appears (just based on the URL format) that you are using a Hikvision device, and those, the
snapShotImageType
is a query parameter, so should be preceded by a?
or&
, according to their user manuals (such as this one). So I think you have your input URL wrong to begin with.Cheers.
This address was in the manual.
Yes you are right. If I delete the "?snapShotImageType=JPEG" is still running.Thanks to all.
-
The problem is the path and the query argument are not the same thing. Everything that goes before the '?' is the path and after it should be set into the setQuery():
const QStringList path_part = path.split('?');
url.setPath(path_part.at(0));
if(path_part.size() > 1)
url.setQuery(path_part.at(1));This will work properly. A path with ? would indeed get encoded with %3F