PTLib  Version 2.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PHTTPClient Class Reference

A TCP/IP socket for the HyperText Transfer Protocol version 1.0. More...

#include <http.h>

Inheritance diagram for PHTTPClient:
PHTTP PInternetProtocol PIndirectChannel PChannel PObject

Public Member Functions

 PHTTPClient (const PString &userAgentName=PString::Empty())
 Create a new HTTP client channel.
int ExecuteCommand (Commands cmd, const PURL &url, PMIMEInfo &outMIME, const PString &dataBody, PMIMEInfo &replyMime)
 Send a command and wait for the response header (including MIME fields).
int ExecuteCommand (const PString &cmdName, const PURL &url, PMIMEInfo &outMIME, const PString &dataBody, PMIMEInfo &replyMime)
PBoolean WriteCommand (Commands cmd, const PString &url, PMIMEInfo &outMIME, const PString &dataBody)
 Write a HTTP command to server.
PBoolean WriteCommand (const PString &cmdName, const PString &url, PMIMEInfo &outMIME, const PString &dataBody)
PBoolean ReadResponse (PMIMEInfo &replyMIME)
 Read a response from the server.
PBoolean ReadContentBody (PMIMEInfo &replyMIME, PBYTEArray &body)
 Read the body of the HTTP command.
PBoolean ReadContentBody (PMIMEInfo &replyMIME, PString &body)
PBoolean GetTextDocument (const PURL &url, PString &document, const PString &contentType=PString::Empty())
 Get the document specified by the URL.
PBoolean GetDocument (const PURL &url, PMIMEInfo &outMIME, PMIMEInfo &replyMIME)
 Get the document specified by the URL.
PBoolean GetHeader (const PURL &url, PMIMEInfo &outMIME, PMIMEInfo &replyMIME)
 Get the header for the document specified by the URL.
PBoolean PostData (const PURL &url, PMIMEInfo &outMIME, const PString &data, PMIMEInfo &replyMIME)
 Post the data specified to the URL.
PBoolean PostData (const PURL &url, PMIMEInfo &outMIME, const PString &data, PMIMEInfo &replyMIME, PString &replyBody)
 Post the data specified to the URL.
bool PutTextDocument (const PURL &url, const PString &document, const PString &contentType=PMIMEInfo::TextPlain())
 Put the document specified by the URL.
bool PutDocument (const PURL &url, PMIMEInfo &outMIME, PMIMEInfo &replyMIME)
 Put the document specified by the URL.
bool DeleteDocument (const PURL &url)
 Delete the document specified by the URL.
void SetAuthenticationInfo (const PString &userName, const PString &password)
 Set authentication paramaters to be use for retreiving documents.
void SetPersistent (bool persist=true)
 Set persistent connection mode.
bool GetPersistent () const
 Get persistent connection mode.

Protected Member Functions

PBoolean AssureConnect (const PURL &url, PMIMEInfo &outMIME)
bool InternalReadContentBody (PMIMEInfo &replyMIME, PAbstractArray *body)
- Protected Member Functions inherited from PHTTP
 PHTTP ()
 Create a TCP/IP HTTP protocol channel.
virtual PINDEX ParseResponse (const PString &line)
 Parse a response line string into a response code and any extra info on the line.
- Protected Member Functions inherited from PInternetProtocol
 PInternetProtocol (const char *defaultServiceName, PINDEX cmdCount, char const *const *cmdNames)
- Protected Member Functions inherited from PIndirectChannel
virtual PBoolean OnOpen ()
 This callback is executed when the Open() function is called with open channels.
- Protected Member Functions inherited from PChannel
 PChannel (const PChannel &)
PChanneloperator= (const PChannel &)
virtual PBoolean ConvertOSError (int libcReturnValue, ErrorGroup group=LastGeneralError)
 Convert an operating system error into platform independent error.
int ReadCharWithTimeout (PTimeInterval &timeout)
 Read a character with specified timeout.
PBoolean ReceiveCommandString (int nextChar, const PString &reply, PINDEX &pos, PINDEX start)
PBoolean PXSetIOBlock (PXBlockType type, const PTimeInterval &timeout)
int PXClose ()
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own.

Protected Attributes

PString m_userAgentName
bool m_persist
PString m_userName
PString m_password
PHTTPClientAuthenticationm_authentication

Additional Inherited Members

- Public Types inherited from PHTTP
enum  Commands {
  GET, HEAD, POST, PUT,
  DELETE, TRACE, OPTIONS, CONNECT,
  NumCommands
}
enum  StatusCode {
  Continue = 100, SwitchingProtocols, RequestOK = 200, Created,
  Accepted, NonAuthoritativeInformation, NoContent, ResetContent,
  PartialContent, MultipleChoices = 300, MovedPermanently, MovedTemporarily,
  SeeOther, NotModified, UseProxy, BadRequest = 400,
  UnAuthorised, PaymentRequired, Forbidden, NotFound,
  MethodNotAllowed, NoneAcceptable, ProxyAuthenticationRequired, RequestTimeout,
  Conflict, Gone, LengthRequired, UnlessTrue,
  InternalServerError = 500, NotImplemented, BadGateway, ServiceUnavailable,
  GatewayTimeout
}
- Static Public Member Functions inherited from PHTTP
static const PCaselessStringAllowTag ()
static const PCaselessStringAuthorizationTag ()
static const PCaselessStringContentEncodingTag ()
static const PCaselessStringContentLengthTag ()
static const PCaselessStringContentTypeTag ()
static const PCaselessStringDateTag ()
static const PCaselessStringExpiresTag ()
static const PCaselessStringFromTag ()
static const PCaselessStringIfModifiedSinceTag ()
static const PCaselessStringLastModifiedTag ()
static const PCaselessStringLocationTag ()
static const PCaselessStringPragmaTag ()
static const PCaselessStringPragmaNoCacheTag ()
static const PCaselessStringRefererTag ()
static const PCaselessStringServerTag ()
static const PCaselessStringUserAgentTag ()
static const PCaselessStringWWWAuthenticateTag ()
static const PCaselessStringMIMEVersionTag ()
static const PCaselessStringConnectionTag ()
static const PCaselessStringKeepAliveTag ()
static const PCaselessStringTransferEncodingTag ()
static const PCaselessStringChunkedTag ()
static const PCaselessStringProxyConnectionTag ()
static const PCaselessStringProxyAuthorizationTag ()
static const PCaselessStringProxyAuthenticateTag ()
static const PCaselessStringForwardedTag ()
static const PCaselessStringSetCookieTag ()
static const PCaselessStringCookieTag ()
- Protected Types inherited from PInternetProtocol
enum  StuffState {
  DontStuff, StuffIdle, StuffCR, StuffCRLF,
  StuffCRLFdot, StuffCRLFdotCR
}
- Friends inherited from PObject

Detailed Description

A TCP/IP socket for the HyperText Transfer Protocol version 1.0.

When acting as a client, the procedure is to make the connection to a remote server, then to retrieve a document using the following procedure:


   PHTTPSocket web("webserver");
   if (web.IsOpen()) {
     PINDEX len;
     if (web.GetDocument("http://www.someone.com/somewhere/url", len)) {
       PString html = web.ReadString(len);
       if (!html.IsEmpty())
         ProcessHTML(html);
     }
     else
        PError << "Could not get page." << endl;
   }
   else
      PError << "HTTP conection failed." << endl;
   

Constructor & Destructor Documentation

PHTTPClient::PHTTPClient ( const PString userAgentName = PString::Empty())

Create a new HTTP client channel.

Member Function Documentation

PBoolean PHTTPClient::AssureConnect ( const PURL url,
PMIMEInfo outMIME 
)
protected
bool PHTTPClient::DeleteDocument ( const PURL url)

Delete the document specified by the URL.

Returns
true if document is deleted.
Parameters
urlUniversal Resource Locator for document.
int PHTTPClient::ExecuteCommand ( Commands  cmd,
const PURL url,
PMIMEInfo outMIME,
const PString dataBody,
PMIMEInfo replyMime 
)

Send a command and wait for the response header (including MIME fields).

Note that a body may still be on its way even if lasResponseCode is not 200!

Returns
true if all of header returned and ready to receive body.
int PHTTPClient::ExecuteCommand ( const PString cmdName,
const PURL url,
PMIMEInfo outMIME,
const PString dataBody,
PMIMEInfo replyMime 
)
PBoolean PHTTPClient::GetDocument ( const PURL url,
PMIMEInfo outMIME,
PMIMEInfo replyMIME 
)

Get the document specified by the URL.

Returns
true if document is being transferred.
Parameters
urlUniversal Resource Locator for document.
outMIMEMIME info in request
replyMIMEMIME info in response
PBoolean PHTTPClient::GetHeader ( const PURL url,
PMIMEInfo outMIME,
PMIMEInfo replyMIME 
)

Get the header for the document specified by the URL.

Returns
true if document header is being transferred.
Parameters
urlUniversal Resource Locator for document.
outMIMEMIME info in request
replyMIMEMIME info in response
bool PHTTPClient::GetPersistent ( ) const
inline

Get persistent connection mode.

References m_persist.

PBoolean PHTTPClient::GetTextDocument ( const PURL url,
PString document,
const PString contentType = PString::Empty() 
)

Get the document specified by the URL.

An empty string for the contentType parameter means that any content type is acceptable.

Returns
true if document is being transferred.
Parameters
urlUniversal Resource Locator for document.
documentBody read
contentTypeContent-Type header to expect
bool PHTTPClient::InternalReadContentBody ( PMIMEInfo replyMIME,
PAbstractArray body 
)
protected
PBoolean PHTTPClient::PostData ( const PURL url,
PMIMEInfo outMIME,
const PString data,
PMIMEInfo replyMIME 
)

Post the data specified to the URL.

Returns
true if document is being transferred.
Parameters
urlUniversal Resource Locator for document.
outMIMEMIME info in request
dataInformation posted to the HTTP server.
replyMIMEMIME info in response
PBoolean PHTTPClient::PostData ( const PURL url,
PMIMEInfo outMIME,
const PString data,
PMIMEInfo replyMIME,
PString replyBody 
)

Post the data specified to the URL.

Returns
true if document is being transferred.
Parameters
urlUniversal Resource Locator for document.
outMIMEMIME info in request
dataInformation posted to the HTTP server.
replyMIMEMIME info in response
replyBodyBody of response
bool PHTTPClient::PutDocument ( const PURL url,
PMIMEInfo outMIME,
PMIMEInfo replyMIME 
)

Put the document specified by the URL.

Returns
true if document is being transferred.
Parameters
urlUniversal Resource Locator for document.
outMIMEMIME info in request
replyMIMEMIME info in response
bool PHTTPClient::PutTextDocument ( const PURL url,
const PString document,
const PString contentType = PMIMEInfo::TextPlain() 
)

Put the document specified by the URL.

Returns
true if document is being transferred.
Parameters
urlUniversal Resource Locator for document.
documentBody read
contentTypeContent-Type header to use
PBoolean PHTTPClient::ReadContentBody ( PMIMEInfo replyMIME,
PBYTEArray body 
)

Read the body of the HTTP command.

PBoolean PHTTPClient::ReadContentBody ( PMIMEInfo replyMIME,
PString body 
)
PBoolean PHTTPClient::ReadResponse ( PMIMEInfo replyMIME)

Read a response from the server.

void PHTTPClient::SetAuthenticationInfo ( const PString userName,
const PString password 
)

Set authentication paramaters to be use for retreiving documents.

void PHTTPClient::SetPersistent ( bool  persist = true)
inline

Set persistent connection mode.

References m_persist.

PBoolean PHTTPClient::WriteCommand ( Commands  cmd,
const PString url,
PMIMEInfo outMIME,
const PString dataBody 
)

Write a HTTP command to server.

PBoolean PHTTPClient::WriteCommand ( const PString cmdName,
const PString url,
PMIMEInfo outMIME,
const PString dataBody 
)

Member Data Documentation

PHTTPClientAuthentication* PHTTPClient::m_authentication
protected
PString PHTTPClient::m_password
protected
bool PHTTPClient::m_persist
protected

Referenced by GetPersistent(), and SetPersistent().

PString PHTTPClient::m_userAgentName
protected
PString PHTTPClient::m_userName
protected

The documentation for this class was generated from the following file: