Logo
~Sockets~
~Examples~
~Contact~


HttpGetSocket.cpp

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 2004-2007  Anders Hedstrom
00007 
00008 This library is made available under the terms of the GNU GPL.
00009 
00010 If you would like to use this library in a closed-source application,
00011 a separate license agreement is available. For information about 
00012 the closed-source license agreement for the C++ sockets library,
00013 please visit http://www.alhem.net/Sockets/license.html and/or
00014 email license@alhem.net.
00015 
00016 This program is free software; you can redistribute it and/or
00017 modify it under the terms of the GNU General Public License
00018 as published by the Free Software Foundation; either version 2
00019 of the License, or (at your option) any later version.
00020 
00021 This program is distributed in the hope that it will be useful,
00022 but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024 GNU General Public License for more details.
00025 
00026 You should have received a copy of the GNU General Public License
00027 along with this program; if not, write to the Free Software
00028 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00029 */
00030 #ifdef _WIN32
00031 #pragma warning(disable:4786)
00032 #else
00033 #include <errno.h>
00034 #endif
00035 #include "Utility.h"
00036 #include "Parse.h"
00037 #include "ISocketHandler.h"
00038 #include "HttpGetSocket.h"
00039 
00040 
00041 #ifdef SOCKETS_NAMESPACE
00042 namespace SOCKETS_NAMESPACE {
00043 #endif
00044 
00045 
00046 HttpGetSocket::HttpGetSocket(ISocketHandler& h) : HttpClientSocket(h)
00047 {
00048 }
00049 
00050 
00051 HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& url_in,const std::string& to_file) : HttpClientSocket(h, url_in)
00052 {
00053         if (to_file.size())
00054         {
00055                 SetFilename(to_file);
00056         }
00057         if (!Open(GetUrlHost(),GetUrlPort()))
00058         {
00059                 if (!Connecting())
00060                 {
00061                         Handler().LogError(this, "HttpGetSocket", -1, "connect() failed miserably", LOG_LEVEL_FATAL);
00062                         SetCloseAndDelete();
00063                 }
00064         }
00065 }
00066 
00067 
00068 HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& host,port_t port,const std::string& url,const std::string& to_file) : HttpClientSocket(h)
00069 {
00070         SetUrl(url);
00071         if (to_file.size())
00072         {
00073                 SetFilename(to_file);
00074         }
00075         if (!Open(host, port))
00076         {
00077                 if (!Connecting())
00078                 {
00079                         Handler().LogError(this, "HttpGetSocket", -1, "connect() failed miserably", LOG_LEVEL_FATAL);
00080                         SetCloseAndDelete();
00081                 }
00082         }
00083 }
00084 
00085 
00086 HttpGetSocket::~HttpGetSocket()
00087 {
00088 }
00089 
00090 
00091 void HttpGetSocket::OnConnect()
00092 {
00093         SetMethod( "GET" );
00094         AddResponseHeader( "Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1");
00095         AddResponseHeader( "Accept-Language", "en-us,en;q=0.5");
00096         AddResponseHeader( "Accept-Encoding", "gzip,deflate");
00097         AddResponseHeader( "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
00098         AddResponseHeader( "User-agent", MyUseragent() );
00099 
00100         if (GetUrlPort() != 80 && GetUrlPort() != 443)
00101                 AddResponseHeader( "Host", GetUrlHost() + ":" + Utility::l2string(GetUrlPort()) );
00102         else
00103                 AddResponseHeader( "Host", GetUrlHost() );
00104         SendRequest();
00105 }
00106 
00107 
00108 #ifdef SOCKETS_NAMESPACE
00109 }
00110 #endif
00111 
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4