]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/protocol/http.h
Define __VISUALC__ for ICC under Windows again.
[wxWidgets.git] / 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 /////////////////////////////////////////////////////////////////////////////
7
8 /**
9 @class wxHTTP
10
11 wxHTTP can be used to establish a connection to an HTTP server.
12
13 wxHTTP can thus be used to create a (basic) HTTP @b client.
14
15 @library{wxnet}
16 @category{net}
17
18 @see wxSocketBase, wxURL
19 */
20 class wxHTTP : public wxProtocol
21 {
22 public:
23 /**
24 Default constructor.
25 */
26 wxHTTP();
27
28 /**
29 Destructor will close the connection if connected.
30 */
31 virtual ~wxHTTP();
32
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.
40
41 Currently wxHTTP only supports IPv4.
42
43 For the overload taking wxSockAddress, the @a wait argument is ignored.
44 */
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);
48 //@}
49
50 /**
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.
53
54 @note
55 The header is not case-sensitive, i.e. "CONTENT-TYPE" and "content-type"
56 represent the same header.
57 */
58 wxString GetHeader(const wxString& header) const;
59
60 /**
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
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.
72
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.
80
81 @see wxInputStream
82 */
83 virtual wxInputStream* GetInputStream(const wxString& path);
84
85 /**
86 Returns the HTTP response code returned by the server.
87
88 Please refer to RFC 2616 for the list of responses.
89 */
90 int GetResponse() const;
91
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
109 /**
110 It sets data of a field to be sent during the next request to the HTTP server.
111
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.
114 */
115 void SetHeader(const wxString& header, const wxString& h_data);
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 */
126 bool HasCookies() const;
127
128 /**
129 Set the binary data to be posted to the server.
130
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
171 */
172 bool SetPostText(const wxString& contentType,
173 const wxString& data,
174 const wxMBConv& conv = wxConvUTF8);
175 };
176