开发者

QT http setting a user agent

void MainWindow::on_WowButton_clicked()
{
    http->setHost("开发者_Python百科pastebin.ca");
    http->get("/raw/2072840");
    QString paste(http->readAll());
    ui->textEdit->setText(paste);
}

Now, I want to set user agent for the get request. please tell the proper way to set a user agent .

Thanks !


QHttp is obsolete and depricated. You are required to use QNetworkAccessManager instead.

QNetworkAccessManager* mgr = new QNetworkAccessManager();
....
QNetworkRequest req;
req.setUrl(QUrl("enter url") );
req.setRawHeader( "User-Agent" , "Mozilla Firefox" );

mgr->get(req);

If you still want to use QHttp

QHttpRequestHeader header("GET", QUrl::toPercentEncoding("/raw/2072840"));
header.setValue("User-Agent", "Firefox 4");
http->setHost("qt.nokia.com");
http->request(header);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜