• R/O
  • SSH
  • HTTPS

eirsamples: Commit


Commit MetaInfo

Revision10 (tree)
Time2018-05-04 09:37:02
Authorquiret

Log Message

- updated marketstatcollect with a sample fetch of Bing query stats (just to show off working TLS fetching, WIP)

Change Summary

Incremental Difference

--- marketstatcollect/src/main.cpp (revision 9)
+++ marketstatcollect/src/main.cpp (revision 10)
@@ -1,10 +1,32 @@
11 #include "StdInc.h"
22
33 #include <CFileSystem.h>
4+#include <tidesnet/tidesnet.h>
45 #include <gtaconfig/include.h>
56
67 #include <iostream>
78
9+#include <tidesnet/mbedtls.h>
10+
11+static std::string ReceiveAllBytes( TidesNetwork::NetSocket *socket )
12+{
13+ std::string data;
14+
15+ while ( socket->IsClosed() == false )
16+ {
17+ char buf[ 0x4000 ];
18+
19+ size_t actuallyRead = socket->Read( buf, sizeof(buf) );
20+
21+ if ( actuallyRead > 0 )
22+ {
23+ data.append( buf, actuallyRead );
24+ }
25+ }
26+
27+ return data;
28+}
29+
830 int main( int argc, char *argv )
931 {
1032 std::cout <<
@@ -41,7 +63,41 @@
4163 }
4264
4365 // Initialize up networking.
44- //TODO.
66+ using namespace TidesNetwork;
4567
68+ netManInst netMan;
69+
70+ // Request the statistics data from Bing.
71+ {
72+ netSocketInst remoteSocket = ConnectRemoteTLS( netMan, "ssl.bing.com", 443 );
73+
74+ if ( remoteSocket.is_good() )
75+ {
76+ // Send the request header.
77+ std::string http_request =
78+ "GET /webmaster/api.svc/json/GetQueryStats?siteUrl=http://www.jawa-reisen.de&apikey=";
79+ http_request += bing_webapiKey;
80+ http_request += " HTTP/1.1\r\n";
81+ http_request += "Host: ssl.bing.com\r\n";
82+ http_request += "Connection: close\r\n\r\n"; // request is terminated by an empty line.
83+
84+ remoteSocket->Write( http_request.c_str(), http_request.size() );
85+
86+ // We will not send anything anymore.
87+ //remoteSocket->ShutdownWrites();
88+
89+ // Receive the result.
90+ std::string result = ReceiveAllBytes( remoteSocket );
91+
92+ if ( result.empty() == false )
93+ {
94+ // TODO.
95+ printf( "%s", result.c_str() );
96+ }
97+
98+
99+ }
100+ }
101+
46102 return 0;
47103 }
\ No newline at end of file
Show on old repository browser