我正在嘗試使用google的url shortener API(https://developers.google.com/url-shortener/v1/getting_started#shorten)創建一個使用url shortener的應用程序。問題是我得到一個不好的請求。 以下是錯誤: 錯誤:錯誤下載https://www.googleapis.com/urlshortener/v1/url - 服務器的回覆:錯誤的請求谷歌Qt http差請求
我做了什麼錯? 下面是代碼:
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);
}
}
人? #shortcomment – ddacot