以前月曆上的美夢,現在實現了
2 週前
my 3 or 2 words; thinkness, speakless
【目的】
【觀念】
http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello&langpair=en|ru用該程式送出,會發現回傳 400(responseStatus),猜測應該是結果有問題。
{"responseData": null, "responseDetails": "invalid version", "responseStatus": 400}用 WireShark 觀察,就可看出原來只送出
GET /ajax/services/language/translate HTTP/1.1問題看起來就是後面的 Query String 沒送出讓 Google Translation 弄迷糊了。
http->get(url.path(), file);改成
http->get(url.toEncoded(), file);
【程式】
#include <QtGui/QApplication> #include "dialog.h" #include <QUrl> #include "HttpGet.h" #include <iostream> #include <QDebug> int main(int argc, char *argv[]) { QApplication a(argc, argv); Dialog w; w.show(); HttpGet getter; QUrl url("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello&langpair=en|ru"); getter.downloadFile(QUrl(url)); QObject::connect(&getter, SIGNAL(finished()), &a, SLOT(quit())); return a.exec(); }
【結果】
{"responseData": {"translatedText":"привет"}, "responseDetails": null, "responseStatus": 200}
【問題】
【其它】
【參考】
Qt-interest Archive, December 2006 QHttp - problem downloading file
http://lists.trolltech.com/qt-interest/2006-12/thread00553-0.html
Ed32. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com