PTLib Version 2.12.9

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PHTTPClient Class Reference

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

`#include <http.h>`

Inheritance diagram for PHTTPClient:
[legend]
Collaboration diagram for PHTTPClient:
[legend]

## Classes
struct | ContentProcessor
| Call back to process the body of the HTTP command. More...

## Public Member Functions
| PHTTPClient (const PString &userAgentName=PString::Empty())
| Create a new HTTP client channel. More...
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). More...
int | ExecuteCommand (const PString &cmdName, const PURL &url, PMIMEInfo &outMIME, const PString &dataBody, PMIMEInfo &replyMime)
bool | WriteCommand (Commands cmd, const PString &url, PMIMEInfo &outMIME, const PString &dataBody)
| Write a HTTP command to server. More...
bool | WriteCommand (const PString &cmdName, const PString &url, PMIMEInfo &outMIME, const PString &dataBody)
bool | ReadResponse (PMIMEInfo &replyMIME)
| Read a response from the server. More...
bool | ReadContentBody (PMIMEInfo &replyMIME, ContentProcessor &processor)
| Read the body of the HTTP command. More...
bool | ReadContentBody (PMIMEInfo &replyMIME)
| Read the body of the HTTP command, throwing it away. More...
bool | ReadContentBody (PMIMEInfo &replyMIME, PString &body)
| Read the body of the HTTP command as a string. More...
bool | ReadContentBody (PMIMEInfo &replyMIME, PBYTEArray &body)
| Read the body of the HTTP command as a binary block. More...
bool | GetDocument (const PURL &url, ContentProcessor &processor)
| Start getting the document specified by the URL. More...
bool | GetDocument (const PURL &url, PMIMEInfo &outMIME, PMIMEInfo &replyMIME)
| Start getting the document specified by the URL. More...
bool | GetDocument (const PURL &url, PMIMEInfo &replyMIME)
bool | GetTextDocument (const PURL &url, PString &document, const PString &contentType=PString::Empty())
| Get the document specified by the URL. More...
bool | GetBinaryDocument (const PURL &url, PBYTEArray &document, const PString &contentType=PString::Empty())
| Get the document specified by the URL. More...
bool | GetHeader (const PURL &url, PMIMEInfo &outMIME, PMIMEInfo &replyMIME)
| Get the header for the document specified by the URL. More...
bool | GetHeader (const PURL &url, PMIMEInfo &replyMIME)
bool | PostData (const PURL &url, const PStringToString &data)
| Post the "application/x-www-form-urlencoded" data specified to the URL. More...
bool | PostData (const PURL &url, PMIMEInfo &outMIME, const PString &data)
| Post the data specified to the URL. More...
bool | PostData (const PURL &url, PMIMEInfo &outMIME, const PString &data, PMIMEInfo &replyMIME)
| Start a post of the data specified to the URL. More...
bool | PostData (const PURL &url, PMIMEInfo &outMIME, const PString &data, PMIMEInfo &replyMIME, PString &replyBody)
| Post the data specified to the URL. More...
bool | PutTextDocument (const PURL &url, const PString &document, const PString &contentType=PMIMEInfo::TextPlain())
| Put the document specified by the URL. More...
bool | PutDocument (const PURL &url, PMIMEInfo &outMIME, PMIMEInfo &replyMIME)
| Put the document specified by the URL. More...
bool | DeleteDocument (const PURL &url)
| Delete the document specified by the URL. More...
void | SetAuthenticationInfo (const PString &userName, const PString &password)
| Set authentication paramaters to be use for retreiving documents. More...
void | SetPersistent (bool persist=true)
| Set persistent connection mode. More...
bool | GetPersistent () const
| Get persistent connection mode. More...

## Protected Member Functions
bool | AssureConnect (const PURL &url, PMIMEInfo &outMIME)
Protected Member Functions inherited from PHTTP
| PHTTP ()
| Create a TCP/IP HTTP protocol channel. More...
| PHTTP (const char *defaultServiceName)
virtual PINDEX | ParseResponse (const PString &line)
| Parse a response line string into a response code and any extra info on the line. More...
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. More...
Protected Member Functions inherited from PChannel
| PChannel (const PChannel &)
PChannel & | operator= (const PChannel &)
virtual PBoolean | ConvertOSError (P_INT_PTR libcReturnValue, ErrorGroup group=LastGeneralError)
| Convert an operating system error into platform independent error. More...
int | ReadCharWithTimeout (PTimeInterval &timeout)
| Read a character with specified timeout. More...
PBoolean | ReceiveCommandString (int nextChar, const PString &reply, PINDEX &pos, PINDEX start)
PBoolean | PXSetIOBlock (PXBlockType type, const PTimeInterval &timeout)
P_INT_PTR | GetOSHandleAsInt () const
int | PXClose ()
| PChannel ()
| Create the channel. More...
Protected Member Functions inherited from PObject
| PObject ()
| Constructor for PObject, made protected so cannot ever create one on its own. More...

## Protected Attributes
PString | m_userAgentName
bool | m_persist
PString | m_userName
PString | m_password
PHTTPClientAuthentication * | m_authentication

## Additional Inherited Members
Public Types inherited from PHTTP
enum | Commands { GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, NumCommands }
enum | StatusCode { BadResponse = 1, ContentProcessorError, UnknownTransferEncoding, 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 PCaselessString & | HostTag ()
static const PCaselessString & | AllowTag ()
static const PCaselessString & | AuthorizationTag ()
static const PCaselessString & | ContentEncodingTag ()
static const PCaselessString & | ContentLengthTag ()
static const PCaselessString & | ContentTypeTag ()
static const PCaselessString & | DateTag ()
static const PCaselessString & | ExpiresTag ()
static const PCaselessString & | FromTag ()
static const PCaselessString & | IfModifiedSinceTag ()
static const PCaselessString & | LastModifiedTag ()
static const PCaselessString & | LocationTag ()
static const PCaselessString & | PragmaTag ()
static const PCaselessString & | PragmaNoCacheTag ()
static const PCaselessString & | RefererTag ()
static const PCaselessString & | ServerTag ()
static const PCaselessString & | UserAgentTag ()
static const PCaselessString & | WWWAuthenticateTag ()
static const PCaselessString & | MIMEVersionTag ()
static const PCaselessString & | ConnectionTag ()
static const PCaselessString & | KeepAliveTag ()
static const PCaselessString & | TransferEncodingTag ()
static const PCaselessString & | ChunkedTag ()
static const PCaselessString & | ProxyConnectionTag ()
static const PCaselessString & | ProxyAuthorizationTag ()
static const PCaselessString & | ProxyAuthenticateTag ()
static const PCaselessString & | ForwardedTag ()
static const PCaselessString & | SetCookieTag ()
static const PCaselessString & | CookieTag ()
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

bool 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

  url | Universal 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
| ) |  |

bool PHTTPClient::GetBinaryDocument | ( | const PURL & | url,
|  | PBYTEArray & | 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

  url | Universal Resource Locator for document.
  document | Body read
  contentType | Content-Type header to expect

bool PHTTPClient::GetDocument | ( | const PURL & | url,
|  | ContentProcessor & | processor
| ) |  |

Start getting the document specified by the URL.

This does not return until completed, and continuously calls the ContentProcessor with chunks of data.

Returns
  true if document has successfully been transferred.

Parameters

  url | Universal Resource Locator for document.
  processor | Processor for received body

bool PHTTPClient::GetDocument | ( | const PURL & | url,
|  | PMIMEInfo & | outMIME,
|  | PMIMEInfo & | replyMIME
| ) |  |

Start getting the document specified by the URL.

It is expected that ReadContentBody() is called after this returns to get, or throw away, the data body received.

Returns
  true if document is being transferred.

Parameters

  url | Universal Resource Locator for document.
  outMIME | MIME info in request
  replyMIME | MIME info in response

bool PHTTPClient::GetDocument | ( | const PURL & | url,
|  | PMIMEInfo & | replyMIME
| ) |  |

Parameters

  url | Universal Resource Locator for document.
  replyMIME | MIME info in response

bool 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

  url | Universal Resource Locator for document.
  outMIME | MIME info in request
  replyMIME | MIME info in response

bool PHTTPClient::GetHeader | ( | const PURL & | url,
|  | PMIMEInfo & | replyMIME
| ) |  |

Parameters

  url | Universal Resource Locator for document.
  replyMIME | MIME info in response

bool PHTTPClient::GetPersistent | ( |  | ) | const
| inline

Get persistent connection mode.

References m_persist.

bool 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

  url | Universal Resource Locator for document.
  document | Body read
  contentType | Content-Type header to expect

bool PHTTPClient::PostData | ( | const PURL & | url,
|  | const PStringToString & | data
| ) |  |

Post the "application/x-www-form-urlencoded" data specified to the URL.

The data returned is thrown away.

Returns
  true if document is being transferred.

Parameters

  url | Universal Resource Locator for document.
  data | Information posted to the HTTP server.

bool PHTTPClient::PostData | ( | const PURL & | url,
|  | PMIMEInfo & | outMIME,
|  | const PString & | data
| ) |  |

Post the data specified to the URL.

The data returned is thrown away.

Returns
  true if document is being transferred.

Parameters

  url | Universal Resource Locator for document.
  outMIME | MIME info in request
  data | Information posted to the HTTP server.

bool PHTTPClient::PostData | ( | const PURL & | url,
|  | PMIMEInfo & | outMIME,
|  | const PString & | data,
|  | PMIMEInfo & | replyMIME
| ) |  |

Start a post of the data specified to the URL.

It is expected that ReadContentBody() is called after this returns to get, or throw away, the data body received.

Returns
  true if document is being transferred.

Parameters

  url | Universal Resource Locator for document.
  outMIME | MIME info in request
  data | Information posted to the HTTP server.
  replyMIME | MIME info in response

bool PHTTPClient::PostData | ( | const PURL & | url,
|  | PMIMEInfo & | outMIME,
|  | const PString & | data,
|  | PMIMEInfo & | replyMIME,
|  | PString & | replyBody
| ) |  |

Post the data specified to the URL.

The body of the reply is returned

Returns
  true if document is has been transferred.

Parameters

  url | Universal Resource Locator for document.
  outMIME | MIME info in request
  data | Information posted to the HTTP server.
  replyMIME | MIME info in response
  replyBody | Body 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

  url | Universal Resource Locator for document.
  outMIME | MIME info in request
  replyMIME | MIME 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

  url | Universal Resource Locator for document.
  document | Body read
  contentType | Content-Type header to use

bool PHTTPClient::ReadContentBody | ( | PMIMEInfo & | replyMIME,
|  | ContentProcessor & | processor
| ) |  |

Read the body of the HTTP command.

Parameters

  replyMIME | Reply MIME from server
  processor | Processor for received body

bool PHTTPClient::ReadContentBody | ( | PMIMEInfo & | replyMIME | ) |

Read the body of the HTTP command, throwing it away.

Parameters

  replyMIME | Reply MIME from server

bool PHTTPClient::ReadContentBody | ( | PMIMEInfo & | replyMIME,
|  | PString & | body
| ) |  |

Read the body of the HTTP command as a string.

Parameters

  replyMIME | Reply MIME from server
  body | Received body as a string

bool PHTTPClient::ReadContentBody | ( | PMIMEInfo & | replyMIME,
|  | PBYTEArray & | body
| ) |  |

Read the body of the HTTP command as a binary block.

Parameters

  replyMIME | Reply MIME from server
  body | Received body as binary data

bool 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.

bool PHTTPClient::WriteCommand | ( | Commands | cmd,
|  | const PString & | url,
|  | PMIMEInfo & | outMIME,
|  | const PString & | dataBody
| ) |  |

Write a HTTP command to server.

bool 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:

- http.h