source: ntrip/trunk/BNC/bncnetrequest.cpp@ 1337

Last change on this file since 1337 was 1337, checked in by mervart, 15 years ago

* empty log message *

File size: 2.8 KB
Line 
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
22using namespace std;
23
24// Constructor
25////////////////////////////////////////////////////////////////////////////
26bncNetRequest::bncNetRequest() {
27 _manager = 0;
28 _reply = 0;
29}
30
31// Destructor
32////////////////////////////////////////////////////////////////////////////
33bncNetRequest::~bncNetRequest() {
34 cout << "~bncNetRequest" << endl;
35 delete _reply;
36 delete _manager;
37}
38
39// Network Request
40////////////////////////////////////////////////////////////////////////////
41t_irc bncNetRequest::request(const QUrl& url) {
42
43 // Network Access Manager
44 // ----------------------
45 if (_manager == 0) {
46 _manager = new QNetworkAccessManager(this);
47 }
48 else {
49 return failure;
50 }
51
52 // Network Request
53 // ---------------
54 QNetworkRequest request;
55 request.setUrl(url);
56 request.setRawHeader("Host" , url.host().toAscii());
57 request.setRawHeader("Ntrip-Version", "NTRIP/2.0");
58 request.setRawHeader("User-Agent" , "NTRIP BNC/1.7");
59 if (!url.userName().isEmpty()) {
60 request.setRawHeader("Authorization", "Basic " +
61 (url.userName() + ":" + url.password()).toAscii().toBase64());
62 }
63 request.setRawHeader("Connection" , "close");
64
65 _reply = _manager->get(request);
66
67 connect(_reply, SIGNAL(finished()), this, SLOT(slotReplyFinished()));
68 connect(_reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
69 connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)),
70 this, SLOT(slotError(QNetworkReply::NetworkError)));
71 /// connect(_reply, SIGNAL(sslErrors()), this, SLOT(slotSslErrors()));
72
73
74 return success;
75}
76
77//
78////////////////////////////////////////////////////////////////////////////
79void bncNetRequest::slotReplyFinished() {
80 cout << "slotReplyFinished" << endl;
81 this->deleteLater();
82}
83
84//
85////////////////////////////////////////////////////////////////////////////
86void bncNetRequest::slotReadyRead() {
87 cout << "slotReadyRead" << endl;
88 QByteArray buffer = _reply->readAll();
89 cout << buffer.data();
90}
91
92//
93////////////////////////////////////////////////////////////////////////////
94void bncNetRequest::slotError(QNetworkReply::NetworkError) {
95 cout << "slotError " << _reply->error() << endl
96 << _reply->errorString().toAscii().data() << endl;
97}
98
99//
100////////////////////////////////////////////////////////////////////////////
101void bncNetRequest::slotSslErrors() {
102 cout << "slotSslError" << endl;
103}
104
Note: See TracBrowser for help on using the repository browser.