Execute http get request url for the http get request string of the http get request or empty string in case of failure
| 56 | /// <param name="url">url for the http get request</param> |
| 57 | /// <returns>string of the http get request or empty string in case of failure</returns> |
| 58 | QString VulkanDatabase::httpGet(QString url) |
| 59 | { |
| 60 | manager = new QNetworkAccessManager(NULL); |
| 61 | |
| 62 | QUrl qurl(url); |
| 63 | |
| 64 | if (username != "" && password != "") |
| 65 | { |
| 66 | qurl.setUserName(username); |
| 67 | qurl.setPassword(password); |
| 68 | } |
| 69 | |
| 70 | QNetworkReply* reply = manager->get(QNetworkRequest(qurl)); |
| 71 | |
| 72 | QEventLoop loop; |
| 73 | connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); |
| 74 | loop.exec(QEventLoop::ExcludeUserInputEvents); |
| 75 | |
| 76 | if (reply->error() == QNetworkReply::NoError) |
| 77 | { |
| 78 | QByteArray bytes = reply->readAll(); |
| 79 | QString replyStr(bytes); |
| 80 | delete(manager); |
| 81 | return replyStr; |
| 82 | } |
| 83 | else |
| 84 | { |
| 85 | QString err; |
| 86 | err = reply->errorString(); |
| 87 | delete(manager); |
| 88 | return ""; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /// <summary> |
| 93 | /// Encodes an url (or string) to make it comply to RFC2396 by replacing |