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);
精彩评论