Version: 2.9.4
Public Member Functions
wxHTTP Class Reference

#include </home/zeitlin/src/wx/github/interface/wx/protocol/http.h>

Inheritance diagram for wxHTTP:

Detailed Description

wxHTTP can be used to establish a connection to an HTTP server.

wxHTTP can thus be used to create a (basic) HTTP client.

Library:  wxNet
Category:  Networking
参照:
wxSocketBase, wxURL

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 wxInputStreamGetInputStream (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.

List of all members.


Constructor & Destructor Documentation

wxHTTP::wxHTTP ( )

Default constructor.

virtual wxHTTP::~wxHTTP ( ) [virtual]

Destructor will close the connection if connected.


Member Function Documentation

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.

wxString wxHTTP::GetCookie ( const wxString cookie) const

Returns the value of a cookie.

wxString wxHTTP::GetHeader ( const wxString header) const

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.

注:
The header is not case-sensitive, i.e. "CONTENT-TYPE" and "content-type" represent the same header.
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.

Returns:
Returns the initialized stream. You must delete it yourself once you don't use it anymore and this must be done before the wxHTTP object itself is destroyed. The destructor closes the network connection. The next time you will try to get a file the network connection will have to be reestablished, but you don't have to take care of this since wxHTTP reestablishes it automatically.
参照:
wxInputStream

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.

void wxHTTP::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.

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.

Parameters:
contentTypeThe value of HTTP "Content-Type" header, e.g. "image/png".
dataThe data to post.
Returns:
true if any data was passed in or false if the buffer was empty.
Since:
2.9.4
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.

Parameters:
contentTypeThe value of HTTP "Content-Type" header, e.g. "text/html; charset=UTF-8".
dataThe data to post.
convThe conversion to use to convert data contents to a byte stream. Its value should be consistent with the charset parameter specified in contentType.
Returns:
true if string was non-empty and was successfully converted using the given conv or false otherwise (in this case this request won't be POST'ed correctly).
Since:
2.9.4
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines