📄 myhttpclient.h
字号:
size_t ActualPostedByte (void) const throw (Exception &) ;
/*! \brief Returns the number of bytes to send to a HTTP web server */
size_t TotalByte (void) const throw (Exception &) ;
/*! \brief Returns the number of bytes posted to a HTTP web server */
size_t PostedByte (void) const throw (Exception &) ;
/*! \brief Returns the total number of parameters */
DWORD TotalCount (void) const throw (Exception &) ;
/*! \brief Returns the number of posted parameters */
DWORD PostedCount (void) const throw (Exception &) ;
/*! \brief Returns the number of file parameters */
DWORD FileCount (void) const throw (Exception &) ;
/*! \brief Returns the number of posted file parameters */
DWORD PostedFileCount (void) const throw (Exception &) ;
/*! \brief Returns the current parameter name */
PCSZ CurrParam (void) const throw (Exception &) ;
/*! \brief Returns the current file path */
PCSZ CurrFile (void) const throw (Exception &) ;
/*! \brief Returns the number of bytes of the current parameter */
size_t CurrParamTotalByte (void) const throw (Exception &) ;
/*! \brief Returns the number of posted bytes of the current parameter */
size_t CurrParamPostedByte (void) const throw (Exception &) ;
/*! \brief Returns the number of remained bytes of the current parameter */
size_t CurrParamRemainByte (void) const throw (Exception &) ;
/*! \brief Returns whether the current parameter is a file parameter */
BOOL CurrParamIsFile (void) const throw (Exception &) ;
/*! \brief Returns whether the current parameter is completely posted */
BOOL CurrParamIsComplete (void) const throw (Exception &) ;
/*! \brief Assignment operator. */
CHttpPostStatT & operator= (const CHttpPostStatT & objPostStat) throw () ;
private:
friend CHttpClientT<HttpTool, CHttpEncoderA> ;
friend CHttpClientT<HttpTool, CHttpEncoderW> ;
void _InitMemberVariables (void) throw () ;
void _SetString (PSZ * pszDest, PCSZ szSrc) throw () ;
/*! \internal \brief Returns TRUE if all bytes are sent */
BOOL _IsComplete (void) const throw () ;
/*! \internal \brief Tests whether the m_cbActualPosted is safe to increase. */
void _TestAddActualPostedBytes (size_t nBytes) throw (Exception &) ;
/*! \internal \brief Increases only m_cbActualPosted */
void _AddActualPostedBytes (size_t nBytes) throw (Exception &) ;
/*! \internal \brief Cleans all internal states and closes the POST state */
void _MakeUnActive (void) throw () ;
/*! \internal \brief Starts a new state of the HTTP POST */
void _MakeActive (size_t cbActualTotal, size_t cbTotal, DWORD cParam, DWORD cFile) throw () ;
/*! \internal \brief Tests whether a new current parameter is safely set */
void _TestStartNewEntry (PCSZ szCurrParam, size_t cbCurrParam, BOOL bIsFile = FALSE, PCSZ szCurrFile = NULL) throw (Exception &) ;
/*! \internal \brief Sets a new current parameter */
void _StartNewEntry (PCSZ szCurrParam, size_t cbCurrParam, BOOL bIsFile = FALSE, PCSZ szCurrFile = NULL) throw (Exception &) ;
/*! \internal \brief Increases all counter related to the number of posted bytes */
void _TestAddPostedBytes (size_t nBytes) throw (Exception &) ;
/*! \internal \brief Increases all counter related to the number of posted bytes */
void _AddPostedBytes (size_t nBytes) throw (Exception &) ;
BOOL m_bIsActive ; //!< Whether the POST is in progress
size_t m_cbActualTotal ; //!< The actual total number of bytes
size_t m_cbActualPosted ; //!< The actual number of posted bytes
size_t m_cbTotal ; //!< The total number of bytes
size_t m_cbPosted ; //!< The number of posted bytes
DWORD m_cParam ; //!< The number of parameters
DWORD m_cParamPosted ; //!< The number of posted parameters (includes the current parameter)
DWORD m_cFile ; //!< The number of file parameters
DWORD m_cFilePosted ; //!< The number of posted file parameters
//! (includes the current parameter if the current parameter is a file parameter)
PSZ m_szCurrParam ; //!< The name of the current parameter
PSZ m_szCurrFile ; //!< The file path of the current parameter
size_t m_cbCurrParam ; //!< The total number of bytes of the current parameter
size_t m_cbCurrParamPosted ; //!< The number of posted bytes of the current parameter
} ;
/*! \brief CHttpPostStat class (Ansi version) */
typedef CHttpPostStatT<CHttpToolA> CHttpPostStatA ;
/*! \brief CHttpPostStat class (Unicode version) */
typedef CHttpPostStatT<CHttpToolW> CHttpPostStatW ;
#ifdef UNICODE
/*! \brief CHttpPostStat class (Generic type version) */
typedef CHttpPostStatW CHttpPostStat ;
#else
/*! \brief CHttpPostStat class (Generic type version) */
typedef CHttpPostStatA CHttpPostStat ;
#endif
///////////////////////////////////////// CHttpPostStatT /////////////////////////////////////////
///////////////////////////////////////// CHttpUrlAnalyzer /////////////////////////////////////////
/*!
* \brief This class analyzes a URL into its component parts.
*
* This class analyzes a URL into its component parts and saves information about each parts.
* It always try to analyze the URL to get the best result. It does not check whether the URL is valid.
* The URL itself is not saved.
*
* The following code sample demonstrates the usage of the CHttpUrlAnalyzer class.
* \code
try {
// A URL to analyze
PCTSTR tszUrl = _T ("http://wedding.makeself.net:80/board_story/list.php?frmtext=&frmtarget=title#ck") ;
CHttpUrlAnalyzer objAnalyzer (tszUrl) ;
TCHAR tszBuff[256] ;
_tprintf (_T ("The analyzed URL : %s\n\n"), tszUrl) ;
// Get protocol ("http" is printed)
_tcsncpy (tszBuff, tszUrl + objAnalyzer.ProtocolIdx (), objAnalyzer.ProtocolLen ()) ;
tszBuff[objAnalyzer.ProtocolLen ()] = '\0' ;
_tprintf (_T ("Protocol : %s\n"), tszBuff) ;
// Get server address ("wedding.makeself.net" is printed)
_tcsncpy (tszBuff, tszUrl + objAnalyzer.AddressIdx (), objAnalyzer.AddressLen ()) ;
tszBuff[objAnalyzer.AddressLen ()] = '\0' ;
_tprintf (_T ("Server Address : %s\n"), tszBuff) ;
// Get server port ("80" is printed)
_tcsncpy (tszBuff, tszUrl + objAnalyzer.PortIdx (), objAnalyzer.PortLen ()) ;
tszBuff[objAnalyzer.PortLen ()] = '\0' ;
_tprintf (_T ("Server Port : %s\n"), tszBuff) ;
// Get path ("/board_story/list.php" is printed)
_tcsncpy (tszBuff, tszUrl + objAnalyzer.PathIdx (), objAnalyzer.PathLen ()) ;
tszBuff[objAnalyzer.PathLen ()] = '\0' ;
_tprintf (_T ("Url Path : %s\n"), tszBuff) ;
// Get search string ("?frmtext=&frmtarget=title" is printed)
_tcsncpy (tszBuff, tszUrl + objAnalyzer.SearchIdx (), objAnalyzer.SearchLen ()) ;
tszBuff[objAnalyzer.SearchLen ()] = '\0' ;
_tprintf (_T ("Search string : %s\n"), tszBuff) ;
// Get bookmark ("#ck" is printed)
_tcsncpy (tszBuff, tszUrl + objAnalyzer.BookmarkIdx (), objAnalyzer.BookmarkLen ()) ;
tszBuff[objAnalyzer.BookmarkLen ()] = '\0' ;
_tprintf (_T ("Bookmark : %s\n"), tszBuff) ;
} catch (httpclientexception & e) {
// handle the exception
}
* \endcode
*/
template <typename HttpTool>
class CHttpUrlAnalyzerT
{
public:
typedef typename HttpTool::Exception Exception ; //!< typedef of httpclientexception
typedef typename HttpTool::CharType CharType ; //!< typedef of character type
typedef typename HttpTool::PSZ PSZ ; //!< typedef of null-terminated string
typedef typename HttpTool::PCSZ PCSZ ; //!< typedef of constant null-terminated string
/*! \brief Default constructor */
CHttpUrlAnalyzerT (PCSZ szUrl = NULL, UINT CodePage = CP_ACP) throw (Exception &) ;
/*! \brief Resets all internal states */
void Reset (void) throw () ;
/*! \brief Analyzes a URL into its component parts */
void Analyze (PCSZ szUrl, UINT CodePage = CP_ACP) throw (Exception &) ;
/*! \brief Returns the start index of the protocol part in the URL
*
* This method returns the start index of the protocol part in the URL.
*
* \return The start index of the protocol part.
*/
inline DWORD ProtocolIdx (void) const throw () { return m_nProtocolIdx ; }
/*! \brief Returns the length of the protocol part in the URL.
*
* This method returns the length of the protocol part in the URL.
*
* \return The length of the protocol part.
*/
inline DWORD ProtocolLen (void) const throw () { return m_cchProtocol ; }
/*! \brief Returns the start index of the address part in the URL
*
* This method returns the start index of the address part in the URL.
*
* \return The start index of the address part.
*/
inline DWORD AddressIdx (void) const throw () { return m_nServerAddrIdx ; }
/*! \brief Returns the length of the address part in the URL
*
* This method returns the length of the address part in the URL.
*
* \return The length of the address part.
*/
inline DWORD AddressLen (void) const throw () { return m_cchServerAddr ; }
/*! \brief Returns the start index of the port part in the URL
*
* This method returns the start index of the port part in the URL.
*
* \return The start index of the port part.
*/
inline DWORD PortIdx (void) const throw () { return m_nServerPortIdx ; }
/*! \brief Returns the length of the port part in the URL
*
* This method returns the length of the port part in the URL.
*
* \return The length of the port part.
*/
inline DWORD PortLen (void) const throw () { return m_cchServerPort ; }
/*! \brief Returns the start index of the path part in the URL
*
* This method returns the start index of the path part in the URL.
*
* \return The start index of the path part.
*/
inline DWORD PathIdx (void) const throw () { return m_nUrlPathIdx ; }
/*! \brief Returns the length of the path part in the URL
*
* This method returns the length of the path part in the URL.
*
* \return The length of the path part.
*/
inline DWORD PathLen (void) const throw () { return m_cchUrlPath ; }
/*! \brief Returns the start index of the search string part in the URL
*
* This method returns the start index of the search string part in the URL.
*
* \return The start index of the search string part.
*/
inline DWORD SearchIdx (void) const throw () { return m_nSearchIdx ; }
/*! \brief Returns the length of the search string part in the URL
*
* This method returns the length of the search string part in the URL.
*
* \return The length of the search string part.
*/
inline DWORD SearchLen (void) const throw () { return m_cchSearch ; }
/*! \brief Returns the start index of the bookmark part in the URL
*
* This method returns the start index of the bookmark part in the URL.
*
* \return The start index of the bookmark part.
*/
inline DWORD BookmarkIdx (void) const throw () { return m_nBookmarkIdx ; }
/*! \brief Returns the length of the bookmark part in the URL
*
* This method returns the length of the bookmark part in the URL.
*
* \return The length of the bookmark part.
*/
inline DWORD BookmarkLen (void) const throw () { return m_cchBookmark ; }
private:
DWORD m_nProtocolIdx, m_cchProtocol ;
DWORD m_nServerAddrIdx, m_cchServerAddr ;
DWORD m_nServerPortIdx, m_cchServerPort ;
DWORD m_nUrlPathIdx, m_cchUrlPath ;
DWORD m_nSearchIdx, m_cchSearch ;
DWORD m_nBookmarkIdx, m_cchBookmark ;
} ;
/*! \brief CHttpUrlAnalyzer class (Ansi version) */
typedef CHttpUrlAnalyzerT<CHttpToolA> CHttpUrlAnalyzerA ;
/*! \brief CHttpUrlAnalyzer class (Unicode version) */
typedef CHttpUrlAnalyzerT<CHttpToolW> CHttpUrlAnalyzerW ;
#ifdef UNICODE
/*! \brief CHttpUrlAnalyzer class (Generic type version) */
typedef CHttpUrlAnalyzerW CHttpUrlAnalyzer ;
#else
/*! \brief CHttpUrlAnalyzer class (Generic type version) */
typedef CHttpUrlAnalyzerA CHttpUrlAnalyzer ;
#endif
///////////////////////////////////////// CHttpUrlAnalyzer /////////////////////////////////////////
///////////////////////////////////////// CHttpClientT /////////////////////////////////////////
/*!
* \brief This class helps you to interact with a HTTP web server.
*
* This is a helper class which supports HTTP GET, POST and UPLOAD (multipart/form-data).
*
* \sa CHttpResponseT, CHttpPostStatT
*/
template <typename HttpTool, typename HttpEncoder>
class CHttpClientT
{
public:
// Basic type definition ====================================================
typedef typename HttpTool::Exception Exception ; //!< typedef of httpclientexception
typedef typename HttpTool::CharType CharType ; //!< typedef of character type
typedef typename HttpTool::PSZ PSZ ; //!< typedef of null-terminated string
typedef typename HttpTool::PCSZ PCSZ ; //!<
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -