#include </home/zeitlin/src/wx/github/interface/wx/protocol/http.h>
wxHTTP can be used to establish a connection to an HTTP server.
wxHTTP can thus be used to create a (basic) HTTP client.
Public Member Functions | |
wxHTTP () | |
Default constructor. | |
virtual | ~wxHTTP () |
Destructor will close the connection if connected. | |
wxString | GetHeader (const wxString &header) const |
Returns the data attached with a field whose name is specified by header. | |
virtual wxInputStream * | GetInputStream (const wxString &path) |
Creates a new input stream on the specified path. | |
int | GetResponse () const |
Returns the HTTP response code returned by the server. | |
void | SetHeader (const wxString &header, const wxString &h_data) |
It sets data of a field to be sent during the next request to the HTTP server. | |
wxString | GetCookie (const wxString &cookie) const |
Returns the value of a cookie. | |
bool | HasCookies () const |
Returns true if there were cookies. | |
bool | SetPostBuffer (const wxString &contentType, const wxMemoryBuffer &data) |
Set the binary data to be posted to the server. | |
bool | SetPostText (const wxString &contentType, const wxString &data, const wxMBConv &conv=wxConvUTF8) |
Set the text to be posted to the server. | |
virtual bool | Connect (const wxString &host) |
Connect to the HTTP server. | |
virtual bool | Connect (const wxString &host, unsigned short port) |
Connect to the HTTP server. | |
virtual bool | Connect (const wxSockAddress &addr, bool wait) |
Connect to the HTTP server. |
wxHTTP::wxHTTP | ( | ) |
Default constructor.
virtual wxHTTP::~wxHTTP | ( | ) | [virtual] |
Destructor will close the connection if connected.
virtual bool wxHTTP::Connect | ( | const wxString & | host | ) | [virtual] |
Connect to the HTTP server.
By default, connection is made to the port 80 of the specified host. You may connect to a non-default port by specifying it explicitly using the second overload.
Currently wxHTTP only supports IPv4.
For the overload taking wxSockAddress, the wait argument is ignored.
virtual bool wxHTTP::Connect | ( | const wxString & | host, |
unsigned short | port | ||
) | [virtual] |
Connect to the HTTP server.
By default, connection is made to the port 80 of the specified host. You may connect to a non-default port by specifying it explicitly using the second overload.
Currently wxHTTP only supports IPv4.
For the overload taking wxSockAddress, the wait argument is ignored.
virtual bool wxHTTP::Connect | ( | const wxSockAddress & | addr, |
bool | wait | ||
) | [virtual] |
Connect to the HTTP server.
By default, connection is made to the port 80 of the specified host. You may connect to a non-default port by specifying it explicitly using the second overload.
Currently wxHTTP only supports IPv4.
For the overload taking wxSockAddress, the wait argument is ignored.
Reimplemented from wxSocketClient.
Returns the data attached with a field whose name is specified by header.
If the field doesn't exist, it will return an empty string and not a NULL string.
virtual wxInputStream* wxHTTP::GetInputStream | ( | const wxString & | path | ) | [virtual] |
Creates a new input stream on the specified path.
Notice that this stream is unseekable, i.e. SeekI() and TellI() methods shouldn't be used.
Note that you can still know the size of the file you are getting using wxStreamBase::GetSize(). However there is a limitation: in HTTP protocol, the size is not always specified so sometimes (size_t)-1 can returned to indicate that the size is unknown. In such case, you may want to use wxInputStream::LastRead() method in a loop to get the total size.
Implements wxProtocol.
int wxHTTP::GetResponse | ( | ) | const |
Returns the HTTP response code returned by the server.
Please refer to RFC 2616 for the list of responses.
bool wxHTTP::HasCookies | ( | ) | const |
Returns true if there were cookies.
It sets data of a field to be sent during the next request to the HTTP server.
The field name is specified by header and the content by h_data. This is a low level function and it assumes that you know what you are doing.
bool wxHTTP::SetPostBuffer | ( | const wxString & | contentType, |
const wxMemoryBuffer & | data | ||
) |
Set the binary data to be posted to the server.
If a non-empty buffer is passed to this method, the next request will be an HTTP POST
instead of the default HTTP GET
and the given data will be posted as the body of this request.
For textual data a more convenient SetPostText() can be used instead.
contentType | The value of HTTP "Content-Type" header, e.g. "image/png". |
data | The data to post. |
bool wxHTTP::SetPostText | ( | const wxString & | contentType, |
const wxString & | data, | ||
const wxMBConv & | conv = wxConvUTF8 |
||
) |
Set the text to be posted to the server.
After a successful call to this method, the request will use HTTP POST
instead of the default GET
when it's executed.
Use SetPostBuffer() if you need to post non-textual data.
contentType | The value of HTTP "Content-Type" header, e.g. "text/html; charset=UTF-8". |
data | The data to post. |
conv | The conversion to use to convert data contents to a byte stream. Its value should be consistent with the charset parameter specified in contentType. |
POST'ed
correctly).