Cross-Platform C++

ot::net
class HttpURLConnection  (abstract)

#include "ot/net/HttpURLConnection.h"

ot::net::URLConnection ot::ManagedObject A specialized URLConnection class that represents a connection with a resource specified by a HTTP URL.

HTTP stands for Hyper Text Transfer Protocol, which is defined by RFCs published by the Internet Engineering Task Force.

A HttpURLConnection instance can make only one HTTP request (although this one request may involve several message exchanges if HTTP redirection or authorization is involved). However, HTTP 1.1 introduces persistent connections which can make more effective use of TCP/IP. OpenTop may make use of persistent connections, but this is an implementation detail which is not exposed to the HttpURLConnection interface.




Constructor/Destructor Summary
HttpURLConnection(const URL& url)
         Constructs a HttpURLConnection for the specified HTTP URL.

Method Summary
static bool GetDefaultFollowRedirects()
         Returns the global FollowRedirects value which is used to initialize new HttpURLConnection objects.
 virtual RefPtr< InputStream > getErrorStream() const=0
         Returns an InputStream that contains the output from the HTTP server after an error occurs.
 virtual bool getFollowRedirects() const=0
         Returns a flag indicating whether HTTP redirects will be followed.
 virtual String getRequestMethod() const=0
         Returns the request method.
 virtual int getResponseCode()=0
         Returns the numeric response code returned from the HTTP server.
 virtual String getResponseMessage()=0
         Returns the message text from the HTTP response line.
static void SetDefaultFollowRedirects(bool bFollow)
         Set the global FollowRedirects value which is used to initialize new HttpURLConnection objects.
 virtual void setFollowRedirects(bool bFollow)=0
         Specifies whether or not HTTP redirect responses should be followed.
 virtual void setRequestMethod(const String& method)=0
         Sets the request method that will be transmitted to the HTTP server.

Methods inherited from class ot::ManagedObject
addRef, getRefCount, onFinalRelease, operator=, release

Methods inherited from class ot::net::URLConnection
connect, getContentEncoding, getContentLength, getContentType, getDate, GetDefaultUseCaches, getDoInput, getDoOutput, getHeaderField, getHeaderField, getHeaderFieldCount, getHeaderFieldDate, getHeaderFieldKey, getHeaderFieldLong, getInputStream, getLastModified, getOutputStream, getRequestProperty, getURL, getUseCaches, isConnected, resetHeaderFields, setConnected, SetDefaultUseCaches, setDoInput, setDoOutput, setRequestProperty, setURL, setUseCaches

Enumerations

enum HttpResponseCode { HTTP_ACCEPTED =202,   
  HTTP_BAD_GATEWAY =502,   
  HTTP_BAD_METHOD =405,   
  HTTP_BAD_REQUEST =400,   
  HTTP_CLIENT_TIMEOUT =408,   
  HTTP_CONFLICT =409,   
  HTTP_CREATED =201,   
  HTTP_ENTITY_TOO_LARGE =413,   
  HTTP_FORBIDDEN =403,   
  HTTP_GATEWAY_TIMEOUT =504,   
  HTTP_GONE =410,   
  HTTP_INTERNAL_ERROR =500,   
  HTTP_LENGTH_REQUIRED =411,   
  HTTP_MOVED_PERM =301,   
  HTTP_MOVED_TEMP =302,   
  HTTP_MULT_CHOICE =300,   
  HTTP_NO_CONTENT =204,   
  HTTP_NOT_ACCEPTABLE =406,   
  HTTP_NOT_AUTHORITATIVE =203,   
  HTTP_NOT_FOUND =404,   
  HTTP_NOT_IMPLEMENTED =501,   
  HTTP_NOT_MODIFIED =304,   
  HTTP_OK =200,   
  HTTP_PARTIAL =206,   
  HTTP_PAYMENT_REQUIRED =402,   
  HTTP_PRECON_FAILED =412,   
  HTTP_PROXY_AUTH =407,   
  HTTP_REQ_TOO_LONG =414,   
  HTTP_RESET =205,   
  HTTP_SEE_OTHER =303,   
  HTTP_UNAUTHORIZED =401,   
  HTTP_UNAVAILABLE =503,   
  HTTP_UNSUPPORTED_TYPE =415,   
  HTTP_USE_PROXY =305,   
  HTTP_VERSION =505}   


Constructor/Destructor Detail

HttpURLConnection

 HttpURLConnection(const URL& url)
Constructs a HttpURLConnection for the specified HTTP URL.


Method Detail

GetDefaultFollowRedirects

static bool GetDefaultFollowRedirects()
Returns the global FollowRedirects value which is used to initialize new HttpURLConnection objects. If this has not been explicitly set, the default value is true.

See also:
SetDefaultFollowRedirects()

getErrorStream

virtual RefPtr< InputStreamgetErrorStream() const=0
Returns an InputStream that contains the output from the HTTP server after an error occurs. For example, if a request results in a "404 File Not Found" error, the server may respond with additional useful information. This additional data (if any) will be returned in the error stream.

Returns:
an InputStream or null if no error occurred, or this HttpURLConnection is not yet connected to the HTTP server.

getFollowRedirects

virtual bool getFollowRedirects() const=0
Returns a flag indicating whether HTTP redirects will be followed.

See also:
setFollowRedirects() , SetDefaultFollowRedirects()

getRequestMethod

virtual String getRequestMethod() const=0
Returns the request method.

See also:
setRequestMethod()

getResponseCode

virtual int getResponseCode()=0
Returns the numeric response code returned from the HTTP server. This will attempt to connect to the HTTP server and access the specified resource if it is not already connected.

Refer to the enumeration HttpURLConnection::HttpResponseCode for a list of possible values.

Exceptions:
IOException - is an error occurs while reading from or writing to the HTTP server.
See also:
getResponseMessage()

getResponseMessage

virtual String getResponseMessage()=0
Returns the message text from the HTTP response line. For example, an HTTP response of HTTP/1.1 200 OK will return "OK".

See also:
getResponseCode()

SetDefaultFollowRedirects

static void SetDefaultFollowRedirects(bool bFollow)
Set the global FollowRedirects value which is used to initialize new HttpURLConnection objects. Setting this does not affect any HttpURLConnection objects already constructed.

The default value is @true.

See also:
setFollowRedirects() , GetDefaultFollowRedirects()

setFollowRedirects

virtual void setFollowRedirects(bool bFollow)=0
Specifies whether or not HTTP redirect responses should be followed. The HTTP protocol allows for resources to be moved from one location to another. When this occurs, the original server may respond to the client with a HTTP_MOVED_PERM (301) or HTTP_MOVED_TEMP (302) message. When redirects are enabled, this will cause the resource to be fetched from the new location, otherwise the request will fail with a FileNotFoundException.

See also:
getFollowRedirects()

setRequestMethod

virtual void setRequestMethod(const String& method)=0
Sets the request method that will be transmitted to the HTTP server. The default is GET for input requests and POST for output requests. Other possible alternatives are:- See http://ietf.org/rfc/rfc2616.txt for further information about HTTP request methods.

Exceptions:
ProtocolException - if the request method cannot be set or the passed method is invalid.
See also:
getRequestMethod()


Cross-Platform C++

Found a bug or missing feature? Please email us at support@elcel.com

Copyright © 2000-2003 ElCel Technology   Trademark Acknowledgements