[1297] | 1 | /* -------------------------------------------------------------------------
|
---|
| 2 | * BKG NTRIP Client
|
---|
| 3 | * -------------------------------------------------------------------------
|
---|
| 4 | *
|
---|
| 5 | * Class: bncNetRequest
|
---|
| 6 | *
|
---|
| 7 | * Purpose: Prepare and submit network request
|
---|
| 8 | *
|
---|
| 9 | * Author: L. Mervart
|
---|
| 10 | *
|
---|
| 11 | * Created: 09-Dec-2008
|
---|
| 12 | *
|
---|
| 13 | * Changes:
|
---|
| 14 | *
|
---|
| 15 | * -----------------------------------------------------------------------*/
|
---|
| 16 |
|
---|
| 17 | #include <iostream>
|
---|
| 18 | #include <iomanip>
|
---|
| 19 |
|
---|
| 20 | #include "bncnetrequest.h"
|
---|
| 21 |
|
---|
| 22 | using namespace std;
|
---|
| 23 |
|
---|
| 24 | #define AGENTVERSION "1.7"
|
---|
| 25 |
|
---|
| 26 | // Constructor
|
---|
| 27 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 28 | bncNetRequest::bncNetRequest() {
|
---|
| 29 | _http = 0;
|
---|
| 30 | _buffer = new QBuffer();
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | // Destructor
|
---|
| 34 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 35 | bncNetRequest::~bncNetRequest() {
|
---|
| 36 | delete _buffer;
|
---|
| 37 | delete _http;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | // Network Request
|
---|
| 41 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 42 | t_irc bncNetRequest::request(const QUrl& url, const QByteArray& ggaStr) {
|
---|
| 43 |
|
---|
| 44 | // Network Access Manager
|
---|
| 45 | // ----------------------
|
---|
| 46 | if (_http == 0) {
|
---|
| 47 | _http = new QHttp();
|
---|
| 48 | }
|
---|
| 49 | else {
|
---|
| 50 | return failure;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | connect(_http, SIGNAL(done(bool)), this, SLOT(slotDone(bool)));
|
---|
| 54 |
|
---|
| 55 | connect(_http, SIGNAL(sslErrors(const QList<QSslError>&)),
|
---|
| 56 | this, SLOT(slotSslErrors(const QList<QSslError>&)));
|
---|
| 57 |
|
---|
| 58 | // Proxy
|
---|
| 59 | // -----
|
---|
| 60 | QSettings settings;
|
---|
| 61 | QString proxyHost = settings.value("proxyHost").toString();
|
---|
| 62 | if (proxyHost.isEmpty()) {
|
---|
| 63 | QNetworkProxy proxy(QNetworkProxy::NoProxy);
|
---|
| 64 | _http->setProxy(proxy);
|
---|
| 65 | }
|
---|
| 66 | else {
|
---|
| 67 | QNetworkProxy proxy(QNetworkProxy::Socks5Proxy);
|
---|
| 68 | proxy.setHostName(proxyHost);
|
---|
| 69 | proxy.setPort(settings.value("proxyPort").toInt());
|
---|
| 70 | _http->setProxy(proxy);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | cout << url.toEncoded().data() << endl;
|
---|
| 74 |
|
---|
| 75 | _http->setHost("www.igs-ip.net");
|
---|
| 76 | _http->get("/", _buffer);
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 | return success;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | //
|
---|
| 83 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 84 | void bncNetRequest::slotDone(bool error) {
|
---|
| 85 | if (error) {
|
---|
| 86 | cout << "slotDone ERROR " << _http->error() << endl
|
---|
| 87 | << _http->errorString().toAscii().data() << endl
|
---|
| 88 | << _http->lastResponse().toString().toAscii().data() << endl;
|
---|
| 89 | }
|
---|
| 90 | else {
|
---|
| 91 | cout << "slotDone OK" << endl;
|
---|
| 92 | }
|
---|
| 93 | cout << "Buffer >" << _buffer->data().data() << "<" << endl;
|
---|
| 94 | this->deleteLater();
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | //
|
---|
| 98 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 99 | void bncNetRequest::slotSslErrors(const QList<QSslError>&) {
|
---|
| 100 | cout << "slotSslError" << endl;
|
---|
| 101 | }
|
---|
| 102 |
|
---|