Qt向YouTube api请求,不支持utf8字符

时间:2012-02-19 14:41:03

标签: c++ qt https youtube-api

我正在用Qt做简单的get请求,但是returend响应是gibrich,这部分不是英语。 当我通过浏览器调用相同的请求时,每件事情都很好,我得到了正确的答案 我在这里失踪了什么? 这是代码和YouTube Api电话 API:
https://gdata.youtube.com/feeds/api/videos/cDholGGVc1M?v=2&alt=jsonc(或json)

这就是我在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

1 个答案:

答案 0 :(得分:1)

这是一个编码问题。使用它来获得Gibrich的UTF-8表示:

ApiResponse.append(QString::fromUtf8(data));

而不是将数据直接输入您的ApiResponse。