|
virtual AutoPtr< HttpConnection > | createConnection (const String &inHostName, u16 inPort=80)=0 |
|
virtual AutoPtr< HttpConnection > | createSecureConnection (const String &inHostName, u16 inPort=443, bool inVerifyServer=false)=0 |
|
virtual AutoPtr< HttpStorage > | createHttpStorage (const String &inUrl, bool inVerifyServer=false, DuplicateStreamCallback inLoadCallback=NULL, void *inContext=NULL) |
|
virtual void | setProxy (ProxyType inType, const String &inHostName="", u16 inPort=0)=0 |
|
virtual CredentialProvider * | getCredentialProvider ()=0 |
|
void | downloadFile (const String &inSaveFileName, const String &inUrl, bool inVerifyServer=false, DuplicateStreamCallback inLoadCallback=NULL, void *inContext=NULL) |
|
| Referable () |
|
void | addRef () const |
|
void | releaseRef () const |
|
size_t | getReferenceCount () const |
|
This class manages the HTTP configurations and create connections. The following sample tries to fetch the index page of http://www.celartem.com
.
void fetchPage(SimpleArray<u8>& buffer)
{
Autoptr<HttpManager> httpMan
AutoPtr<HttpConnection> conn
= httpMan->createConnection("www.celartem.com");
AutoPtr<HttpRequestStream> req
= conn->createRequestStream("GET", "/");
AutoPtr<HttpResponseStream> res = req->post();
unsigned int ret = res->getStatusCode();
if(ret / 100 != 2)
size_t size = res->getContentSize();
buffer.allocate(size);
res->readBytes(&buffer[0], size);
}
Please note that this sample is just to indicate how to use createConnection, HttpRequestStream and HttpResponseStream, there are another way to do it easier; for more information, see createHttpStorage .
- See Also
- HttpConnection, HttpRequestStream, HttpResponseStream
This method create read-only storage based on HTTP connection. Whether using HTTP or HTTPS is automatically determined by examining scheme specification in the URL.
The storage created by this method internally uses HttpConnection. This method is thread-safe; all the calls to this method is automatically serialized.
- Parameters
-
inUrl | URL of the resource to access. It should be escaped before passing to this method. |
inVerifyServer | Whether the server connected to should be verified or not. |
inLoadCallback | Callback function called during fetching the data from the HTTP connection. |
inContext | Context used on the callback. |
- Returns
- Pointer to the newly created Storage instance.
- See Also
- Url, createConnection, createSecureConnection
The following is a sample use of this method:
void fetchPage(SimpleArray<u8>& buffer)
{
AutoPtr<HttpManager> httpMan
AutoPtr<HttpStorage> storage
= httpMan->createHttpStorage("http://www.example.com/test/picture.tif");
size_t size = storage->getSize();
buffer.allocate(size + 1);
storage->readBytes(&buffer[0], size);
buffer[size] = 0;
}
Although almost same function can be realized by createConnection method, this one is more straightforward and easy than it.