1
我用Qt做簡單的請求,但returend響應在gibrich中,不是英文的部分。 當我通過瀏覽器調用相同的請求每件事情都很好,我得到正確的迴應 什麼我在這裏失蹤? 這裏是代碼和YouTube Api調用。
的API:
https://gdata.youtube.com/feeds/api/videos/cDholGGVc1M?v=2&alt=jsonc(或JSON)Qt做得到YouTube api請求,不支持utf8字符
這是我如何調用它使用Qt
QUrl getUrl("https://gdata.youtube.com/feeds/api/videos/cDholGGVc1M?v=2&alt=jsonc");
QNetworkRequest request;
request.setRawHeader("User-Agent", USER_AGENT.toUtf8());
request.setRawHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
request.setRawHeader("Accept-Language", "en-us,en;q=0.5");
request.setRawHeader("Connection", "Keep-Alive");
request.setUrl(getUrl);
QEventLoop loop;
//This tell the request only to cuntinue after all response is done
QNetworkReply *reply = networkManager->get(request);
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
//return response
QByteArray data=reply->readAll();
ApiResponse.append(data); // HERE IS ALL GIBRISH