Public Member Functions

# wxHTTP Class Reference
[Networking]

`#include <wx/protocol/http.h>`

Inheritance diagram for wxHTTP:
[legend]

## 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

See also:
  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 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.
void | SetPostBuffer (const wxString &post_buf)
| Set the data 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.

Note:
  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.

See also:
  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.

void wxHTTP::SetPostBuffer | ( | const wxString & | post_buf | ) |

Set the data to be posted to the server.

If a non-empty string is passed to this method, the next request will be an HTTP `POST` instead of the default HTTP `GET` and the data from post_buf will be posted as the body of this request.

|  | [ top ]