简体   繁体   中英

QNetworkRequest and QUrl encoding c++

Im trying to connect to gmail and consume the atom file. Im having problem with passwords that contain !#$%^&* chars.

    pNetworkManager = new QNetworkAccessManager(this);

    connect(pNetworkManager, SIGNAL(finished(QNetworkReply*)), 
            this, SLOT(result(QNetworkReply*)));

    Settings settings;
    settings.load();
    QString url;

    url.append("https://");
    url.append(settings.getUserName());
    url.append(":");
    url.append(QUrl::toPercentEncoding(settings.getPassword()));
    url.append("@mail.google.com/mail/feed/atom");


    pNetworkManager->get(QNetworkRequest(QUrl(url.toUtf8())));

I get reply "Protocol "" is unknown"
Qt 4.8

How is this done properly

Why don't you construct a QUrl directly?

QUrl url("https://mail.google.com/mail/feed/atom");
url.setUserName(settings.getUserName());
url.setPassword(settings.getPassword());
pNetworkManager->get(QNetworkRequest(url));

It handles all the necessary encoding and QNetworkRequest takes it directly anyway. No need to mess with string encodings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM