我正在尝试使用QT框架运行多重查询。 我的查询看起来像这样
{"query1":"SELECT uid2 FROM friend WHERE uid1=me()","query2":"SELECT uid, name FROM user WHERE uid in(SELECT uid2 FROM #query1)"}
到目前为止,我发现如果不使用“#query1”方法,它将起作用。但我在我的应用程序中需要它,因为我的实际查询更复杂。
如果我粘贴
https://api.facebook.com/method/fql.multiquery?format=json&queries=%7B%22query1%22%3A%22SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%3Dme%28%29%22%2C%22query2%22%3A%22SELECT%20uid%2C%20name%20FROM%20user%20WHERE%20uid%20in%28SELECT%20uid2%20FROM%20%23query1%29%22%7D&access_token=xxxxxxxxxxxxx
在浏览器的地址栏中,其中access_token是有效的,我得到了我的回复。
当我从QT发出相同的请求时,我得到一个空的json列表(“[]”)
这是QT代码:
//this is just a markup, the read deal works
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkRequest request;
url="https://api.facebook.com/method/fql.multiquery?format=json&queries=%7B%22query1%22%3A%22SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%3Dme%28%29%22%2C%22query2%22%3A%22SELECT%20uid%2C%20name%20FROM%20user%20WHERE%20uid%20in%28SELECT%20uid2%20FROM%20%23query1%29%22%7D&access_token=xxxxxxxxxxxxx";
request.setRawHeader("Content-Type","application/x-www-form-urlencoded");
request.setUrl(url);
reply=manager->get(request);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
void replyFinished(QNetworkReply *r){
qDebug()<<r->readAll();
}
目前输出“[]”。 如果我使用像
这样的简单网址它运作得很好。
那我错过了什么?
是因为浏览器的get请求之间存在差异 我的QT获得请求?
我是否必须配置HTTP get请求的标头?什么
如果是这样的价值?
提前谢谢
答案 0 :(得分:0)
网址已经过编码,您应该使用QUrl::setEncodedUrl()
进行设置,或让QUrl
为您编码:
url = "https://api.facebook.com/method/fql.multiquery?format=json&queries={\"query1\":\"SELECT uid2 FROM friend WHERE uid1=me()\",\"query2\":\"SELECT uid, name FROM user WHERE uid in(SELECT uid2 FROM #query1)\"}&access_token=xxxxxxxxxxxxx";