]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/protocol/http.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: protocol/http.h
3 // Purpose: interface of wxHTTP
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
11 wxHTTP can be used to establish a connection to an HTTP server.
13 wxHTTP can thus be used to create a (basic) HTTP @b client.
18 @see wxSocketBase, wxURL
20 class wxHTTP
: public wxProtocol
29 Destructor will close the connection if connected.
35 Connect to the HTTP server.
37 By default, connection is made to the port 80 of the specified @a host.
38 You may connect to a non-default port by specifying it explicitly using
41 Currently wxHTTP only supports IPv4.
43 For the overload taking wxSockAddress, the @a wait argument is ignored.
45 virtual bool Connect(const wxString
& host
);
46 virtual bool Connect(const wxString
& host
, unsigned short port
);
47 virtual bool Connect(const wxSockAddress
& addr
, bool wait
);
51 Returns the data attached with a field whose name is specified by @a header.
52 If the field doesn't exist, it will return an empty string and not a @NULL string.
55 The header is not case-sensitive, i.e. "CONTENT-TYPE" and "content-type"
56 represent the same header.
58 wxString
GetHeader(const wxString
& header
) const;
61 Creates a new input stream on the specified path.
63 Notice that this stream is unseekable, i.e. SeekI() and TellI() methods
66 Note that you can still know the size of the file you are getting using
67 wxStreamBase::GetSize(). However there is a limitation: in HTTP protocol,
68 the size is not always specified so sometimes @c (size_t)-1 can returned to
69 indicate that the size is unknown.
70 In such case, you may want to use wxInputStream::LastRead() method in a loop
71 to get the total size.
73 @return Returns the initialized stream. You must delete it yourself
74 once you don't use it anymore and this must be done before
75 the wxHTTP object itself is destroyed. The destructor
76 closes the network connection. The next time you will
77 try to get a file the network connection will have to
78 be reestablished, but you don't have to take care of
79 this since wxHTTP reestablishes it automatically.
83 virtual wxInputStream
* GetInputStream(const wxString
& path
);
86 Returns the HTTP response code returned by the server.
88 Please refer to RFC 2616 for the list of responses.
90 int GetResponse() const;
95 Set <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html">common</a>
96 or expanded HTTP method.
98 Overrides GET or POST methods that is used by default.
101 HTTP method name, e.g. "GET".
105 @see SetPostBuffer(), SetPostText()
107 void SetMethod(const wxString
& method
);
110 It sets data of a field to be sent during the next request to the HTTP server.
112 The field name is specified by @a header and the content by @a h_data.
113 This is a low level function and it assumes that you know what you are doing.
115 void SetHeader(const wxString
& header
, const wxString
& h_data
);
118 Returns the value of a cookie.
121 wxString
GetCookie(const wxString
& cookie
) const;
124 Returns @true if there were cookies.
126 bool HasCookies() const;
129 Set the binary data to be posted to the server.
131 If a non-empty buffer is passed to this method, the next request will
132 be an HTTP @c POST instead of the default HTTP @c GET and the given @a
133 data will be posted as the body of this request.
135 For textual data a more convenient SetPostText() can be used instead.
138 The value of HTTP "Content-Type" header, e.g. "image/png".
142 @true if any data was passed in or @false if the buffer was empty.
146 bool SetPostBuffer(const wxString
& contentType
, const wxMemoryBuffer
& data
);
149 Set the text to be posted to the server.
151 After a successful call to this method, the request will use HTTP @c
152 POST instead of the default @c GET when it's executed.
154 Use SetPostBuffer() if you need to post non-textual data.
157 The value of HTTP "Content-Type" header, e.g. "text/html;
162 The conversion to use to convert @a data contents to a byte stream.
163 Its value should be consistent with the charset parameter specified
166 @true if string was non-empty and was successfully converted using
167 the given @a conv or @false otherwise (in this case this request
168 won't be @c POST'ed correctly).
172 bool SetPostText(const wxString
& contentType
,
173 const wxString
& data
,
174 const wxMBConv
& conv
= wxConvUTF8
);