Possible duplicate QuestionQt QUrlQuery extrait jeton QByteArray
Je générer un lien de réinitialisation/jeton qui sera envoyé par courriel au client comme suit.
QByteArray token;
token.resize(crypto_pwhash_SALTBYTES);
randombytes_buf(token.data(), crypto_pwhash_SALTBYTES);
QUrlQuery token_url("http://localhost:8080/reset/staff");
token_url.addQueryItem("token", token);
token_url.query(QUrl::FullyEncoded).toUtf8();
Cela semble produire la sortie correcte:
http://localhost:8080/reset/staff&token=pc%22%EF%BF%BD%C6%9Fsktx%EF%BF%BD!%06t%5C%0B
Pour authentifier la demande de remise à zéro contre le hachage stocké j'ai besoin du QByteArray jeton.
QByteArray path = request.getPath();
qDebug() << path;
QUrlQuery token_url(path);
QString token(token_url.queryItemValue("token"));
qDebug() << token;
qDebug() << QUrl::fromPercentEncoding(path);
La sortie dont l'URL est collé dans firefox charabia
"/reset/staff&token=pc\"\xEF\xBF\xBD\xC6\x9Fsktx\xEF\xBF\xBD!\x06t\\\x0B"
"pc\"�Ɵsktx�!%06t\\%0B"
"/reset/staff&token=pc\"�Ɵsktx�!\u0006t\\\u000B"
Je comprends que je fais probablement un chien unsigned char converstion.
Quelle est la méthode élégante pour faire passer QBytearrays dans QUrlQuery?
J'ai vu des programmeurs écrire leurs propres analyseurs d'URL, mais cela semble excessif.