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