开发者

QT http setting a user agent

开发者 https://www.devze.com 2023-03-09 18:47 出处:网络
void MainWindow::on_WowButton_clicked() { http->setHost(\"开发者_Python百科pastebin.ca\"); http->get(\"/raw/2072840\");
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

精彩评论

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