Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Qt http bad request on google

$
0
0
I’m trying to create an url shortener app using google’s url shortener api (https://developers.google.com/url-shortener/v1/getting_started#shorten). The problem is that I get a bad request. Here is the error: Error: Error downloading https://www.googleapis.com/urlshortener/v1/url – server replied: Bad Request What did I do wrong? Here is the code: void MainWindow::ppp(QString longurl) {     QNetworkAccessManager* manager = new QNetworkAccessManager(this);     connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));       QUrl url = QUrl("https://www.googleapis.com/urlshortener/v1/url");       QNetworkRequest request(url);     request.setHeader(request.ContentTypeHeader,"application/json");       QByteArray postData;     postData.append("longUrl=");     postData.append(longurl);         manager->post(request,postData); }   void MainWindow::replyFinished(QNetworkReply *reply) {     if(reply->error() != QNetworkReply::NoError)     {         ui->textBrowser->setText("Error: " +  reply->errorString());     }     else     {         QByteArray responseData = reply->readAll();         QString qstr(responseData);         ui->textBrowser->setText(qstr);     } }

Viewing all articles
Browse latest Browse all 13965

Trending Articles