Qt 对 YouTube api 进行 get 请求,不支持 utf8 字符
我用 Qt 做简单的 get 请求,但返回的响应是 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
Im doing simple get request with Qt , but the returend response is in gibrich , the part which isn't english .
when i invoke the same request via browser every thing is fine and i get the right response
what im missing here ?
here is the code and the YouTube Api call.
the API :
https://gdata.youtube.com/feeds/api/videos/cDholGGVc1M?v=2&alt=jsonc ( or json)
this is how i invoke it in 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个编码问题。使用它来获取 Gibrich 的 UTF-8 表示形式:
而不是直接将数据放入 ApiResponse 中。
It's an encoding problem. Use this to get a UTF-8 representation of Gibrich:
rather than taking data directly into your ApiResponse.