4 #ifndef __HttpURLConnection_H
5 #define __HttpURLConnection_H
18 enum HTTP_RESPONSECODE
{
21 HTTP_CONTINUE
= 100, // Everything OK, keep going...
22 HTTP_SWITCH_PROC
= 101, // Switching Protocols
24 HTTP_OK
= 200, // OPTIONS/GET/HEAD/POST/TRACE command was successful
25 HTTP_CREATED
, // PUT command was successful
26 HTTP_ACCEPTED
, // DELETE command was successful
27 HTTP_NOT_AUTHORITATIVE
, // Information isn't authoritative
28 HTTP_NO_CONTENT
, // Successful command, no new data
29 HTTP_RESET
, // Content was reset/recreated
30 HTTP_PARTIAL
, // Only a partial file was recieved/sent
32 HTTP_MULTI_CHOICE
= 300, // Multiple files match request
33 HTTP_MOVED_PERM
, // Document has moved permanently
34 HTTP_MOVED_TEMP
, // Document has moved temporarily
35 HTTP_SEE_OTHER
, // See this other link...
36 HTTP_NOT_MODIFIED
, // File not modified
37 HTTP_USE_PROXY
, // Must use a proxy to access this URI
39 HTTP_BAD_REQUEST
= 400, // Bad request
40 HTTP_UNAUTHORIZED
, // Unauthorized to access host
41 HTTP_PAYMENT_REQUIRED
, // Payment required
42 HTTP_FORBIDDEN
, // Forbidden to access this URI
43 HTTP_NOT_FOUND
, // URI was not found
44 HTTP_BAD_METHOD
, // Method is not allowed
45 HTTP_NOT_ACCEPTABLE
, // Not Acceptable
46 HTTP_PROXY_AUTH
, // Proxy Authentication is Required
47 HTTP_REQUEST_TIMEOUT
, // Request timed out
48 HTTP_CONFLICT
, // Request is self-conflicting
49 HTTP_GONE
, // Server has gone away
50 HTTP_LENGTH_REQUIRED
, // A content length or encoding is required
51 HTTP_PRECON_FAILED
, // Precondition failed
52 HTTP_ENTITY_TOO_LARGE
, // URI too long
53 HTTP_REQ_TOO_LONG
, // Request entity too large
54 HTTP_UNSUPPORTED_TYPE
, // The requested media type is unsupported
56 HTTP_SERVER_ERROR
= 500, // Internal server error
57 HTTP_INTERNAL_ERROR
, // Feature not implemented
58 HTTP_BAD_GATEWAY
, // Bad gateway
59 HTTP_UNAVAILABLE
, // Service is unavailable
60 HTTP_GATEWAY_TIMEOUT
, // Gateway connection timed out
61 HTTP_VERSION
// HTTP version not supported
69 Field(const char *k
, const char *v
);
71 Field
&operator = (const Field
&);
72 bool operator == (const Field
&);
75 typedef list
<Field
> Fields
;
77 class HttpURLConnection
{
79 HttpURLConnection(const URL
&url
);
80 virtual ~HttpURLConnection();
82 virtual void connect();
85 void setRequestMethod(const char *method
);
86 const char *getRequestMethod() const;
87 void setRequestProperty(const char *key
, const char *value
);
89 const char *getContentType();
90 const char *getContentEncoding();
91 int getContentLength();
93 const char *getHeaderField(int n
);
94 const char *getHeaderField(const char *);
95 const URL
&getURL() const;
96 HTTP_RESPONSECODE
getResponseCode();
97 const char *getResponseMessage();
99 bool getDoInput() const;
100 bool getDoOutput() const;
101 void setDoInput(bool doInput
);
102 void setDoOutput(bool doOutput
);
104 istream
&getInputStream();
105 ostream
&getOutputStream();
107 const char *getLastError() const;
108 void setLastError(const char *);
116 virtual void action();
117 virtual void setRequest();
118 virtual void setContent();
119 virtual void getResponse();
120 virtual void getContent();
127 string __response_message
;
128 HTTP_RESPONSECODE __response_code
;
132 inline const char *HttpURLConnection::getLastError() const
134 return __error_msg
.c_str();
137 inline void HttpURLConnection::setLastError(const char *e
)
142 #endif // __HttpURLConnection_H