1 #include <SocketHandler.h>
5 class GetHttp
: public TcpSocket
8 GetHttp(ISocketHandler
& h
, const char *request
) : TcpSocket(h
)
9 , m_request(request
) {}
15 void OnRawData( const char *buf
, size_t len
) {
19 memcpy( &tmp
[0], buf
, len
);
24 const std::string
& Response() {
29 std::string m_request
;
30 std::string m_response
;
34 std::string
get_http(const char *host
, int port
, const char *request
)
37 GetHttp
sock(h
, request
);
38 sock
.Open( host
, port
);
40 while (h
.GetCount()) {
43 return sock
.Response();
47 int main(int argc
, char *argv
[])
49 std::string zz
= get_http("www.alhem.net", 80, "GET /index.html HTTP/1.0\r\n"
50 "Host: www.alhem.net\r\n"
52 printf("%s\n%d\n", zz
.c_str(), zz
.size());