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

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