]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: protocol/http.h | |
e54c96f1 | 3 | // Purpose: interface of wxHTTP |
23324ae1 | 4 | // Author: wxWidgets team |
526954c5 | 5 | // Licence: wxWindows licence |
23324ae1 FM |
6 | ///////////////////////////////////////////////////////////////////////////// |
7 | ||
8 | /** | |
9 | @class wxHTTP | |
7c913512 | 10 | |
a30b5ab9 | 11 | wxHTTP can be used to establish a connection to an HTTP server. |
7c913512 | 12 | |
730b772b FM |
13 | wxHTTP can thus be used to create a (basic) HTTP @b client. |
14 | ||
23324ae1 FM |
15 | @library{wxnet} |
16 | @category{net} | |
7c913512 | 17 | |
e54c96f1 | 18 | @see wxSocketBase, wxURL |
23324ae1 FM |
19 | */ |
20 | class wxHTTP : public wxProtocol | |
21 | { | |
22 | public: | |
730b772b FM |
23 | /** |
24 | Default constructor. | |
25 | */ | |
26 | wxHTTP(); | |
27 | ||
28 | /** | |
29 | Destructor will close the connection if connected. | |
30 | */ | |
31 | virtual ~wxHTTP(); | |
32 | ||
e57337ce VZ |
33 | //@{ |
34 | /** | |
35 | Connect to the HTTP server. | |
36 | ||
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 | |
39 | the second overload. | |
5ba5f329 VZ |
40 | |
41 | Currently wxHTTP only supports IPv4. | |
42 | ||
43 | For the overload taking wxSockAddress, the @a wait argument is ignored. | |
e57337ce | 44 | */ |
882678eb FM |
45 | virtual bool Connect(const wxString& host); |
46 | virtual bool Connect(const wxString& host, unsigned short port); | |
5ba5f329 | 47 | virtual bool Connect(const wxSockAddress& addr, bool wait); |
e57337ce VZ |
48 | //@} |
49 | ||
23324ae1 | 50 | /** |
730b772b | 51 | Returns the data attached with a field whose name is specified by @a header. |
a30b5ab9 FM |
52 | If the field doesn't exist, it will return an empty string and not a @NULL string. |
53 | ||
54 | @note | |
55 | The header is not case-sensitive, i.e. "CONTENT-TYPE" and "content-type" | |
56 | represent the same header. | |
23324ae1 | 57 | */ |
adaaa686 | 58 | wxString GetHeader(const wxString& header) const; |
23324ae1 FM |
59 | |
60 | /** | |
a30b5ab9 FM |
61 | Creates a new input stream on the specified path. |
62 | ||
63 | Notice that this stream is unseekable, i.e. SeekI() and TellI() methods | |
64 | shouldn't be used. | |
65 | ||
7c913512 | 66 | Note that you can still know the size of the file you are getting using |
a30b5ab9 FM |
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. | |
72 | ||
d29a9a8a | 73 | @return Returns the initialized stream. You must delete it yourself |
a30b5ab9 | 74 | once you don't use it anymore and this must be done before |
4cc4bfaf FM |
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. | |
a30b5ab9 | 80 | |
4cc4bfaf | 81 | @see wxInputStream |
23324ae1 | 82 | */ |
adaaa686 | 83 | virtual wxInputStream* GetInputStream(const wxString& path); |
23324ae1 FM |
84 | |
85 | /** | |
a30b5ab9 FM |
86 | Returns the HTTP response code returned by the server. |
87 | ||
88 | Please refer to RFC 2616 for the list of responses. | |
23324ae1 | 89 | */ |
730b772b | 90 | int GetResponse() const; |
23324ae1 | 91 | |
6535170f VZ |
92 | /** |
93 | Set HTTP method. | |
94 | ||
95 | Set <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html">common</a> | |
96 | or expanded HTTP method. | |
97 | ||
98 | Overrides GET or POST methods that is used by default. | |
99 | ||
100 | @param method | |
101 | HTTP method name, e.g. "GET". | |
102 | ||
103 | @since 3.0.0 | |
104 | ||
105 | @see SetPostBuffer(), SetPostText() | |
106 | */ | |
107 | void SetMethod(const wxString& method); | |
108 | ||
23324ae1 FM |
109 | /** |
110 | It sets data of a field to be sent during the next request to the HTTP server. | |
a30b5ab9 | 111 | |
730b772b | 112 | The field name is specified by @a header and the content by @a h_data. |
23324ae1 FM |
113 | This is a low level function and it assumes that you know what you are doing. |
114 | */ | |
115 | void SetHeader(const wxString& header, const wxString& h_data); | |
906cb3f1 JS |
116 | |
117 | /** | |
118 | Returns the value of a cookie. | |
119 | */ | |
120 | ||
121 | wxString GetCookie(const wxString& cookie) const; | |
122 | ||
123 | /** | |
124 | Returns @true if there were cookies. | |
125 | */ | |
906cb3f1 | 126 | bool HasCookies() const; |
d00167e1 VZ |
127 | |
128 | /** | |
ab9d6a4c | 129 | Set the binary data to be posted to the server. |
d00167e1 | 130 | |
ab9d6a4c VZ |
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. | |
134 | ||
135 | For textual data a more convenient SetPostText() can be used instead. | |
136 | ||
137 | @param contentType | |
138 | The value of HTTP "Content-Type" header, e.g. "image/png". | |
139 | @param data | |
140 | The data to post. | |
141 | @return | |
142 | @true if any data was passed in or @false if the buffer was empty. | |
143 | ||
144 | @since 2.9.4 | |
145 | */ | |
146 | bool SetPostBuffer(const wxString& contentType, const wxMemoryBuffer& data); | |
147 | ||
148 | /** | |
149 | Set the text to be posted to the server. | |
150 | ||
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. | |
153 | ||
154 | Use SetPostBuffer() if you need to post non-textual data. | |
155 | ||
156 | @param contentType | |
157 | The value of HTTP "Content-Type" header, e.g. "text/html; | |
158 | charset=UTF-8". | |
159 | @param data | |
160 | The data to post. | |
161 | @param conv | |
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 | |
164 | in @a contentType. | |
165 | @return | |
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). | |
169 | ||
170 | @since 2.9.4 | |
d00167e1 | 171 | */ |
ab9d6a4c VZ |
172 | bool SetPostText(const wxString& contentType, |
173 | const wxString& data, | |
174 | const wxMBConv& conv = wxConvUTF8); | |
23324ae1 | 175 | }; |
e54c96f1 | 176 |