2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FNetHttpHttpUrlEncodedEntity.h
20 * @brief This is the header file for the %HttpUrlEncodedEntity class.
22 * This header file contains the declarations of the %HttpUrlEncodedEntity class.
25 #ifndef _FNET_HTTP_HTTP_URL_ENCODED_ENTITY_H_
26 #define _FNET_HTTP_HTTP_URL_ENCODED_ENTITY_H_
28 #include <FNetHttpHttpTypes.h>
29 #include <FNetHttpIHttpEntity.h>
31 namespace Tizen { namespace Base
37 namespace Tizen { namespace Text
42 namespace Tizen { namespace Net { namespace Http
44 class _HttpUrlEncodedEntityImpl;
47 * @class HttpUrlEncodedEntity
48 * @brief This class represents an http body for urlencoded pairs (name and value).
52 * The %HttpUrlEncodedEntity class represents an http body for urlencoded pairs (name and value).
54 * The following example demonstrates how to use the %HttpUrlEncodedEntity class to send content for urlencoded pairs to the server.
61 using namespace Tizen::Base;
62 using namespace Tizen::Net::Http;
65 TestHttpUrlEncodedEntity(void)
69 HttpSession* pSession = null;
70 HttpTransaction* pTransaction = null;
71 HttpRequest* pRequest = null;
72 String hostAddr(L"http://www.tizen.org");
74 pSession = new HttpSession();
75 r = pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, null, hostAddr, null);
77 pTransaction = pSession->OpenTransactionN();
78 r = pTransaction->AddHttpTransactionListener(*this);
80 pRequest = const_cast<HttpRequest*>(pTransaction->GetRequest());
81 r = pRequest->SetUri(L"http://www.tizen.org/test");
82 r = pRequest->SetMethod(NET_HTTP_METHOD_POST);
84 HttpUrlEncodedEntity* pHttpUrlEncodedEntity = new HttpUrlEncodedEntity();
85 r = pHttpUrlEncodedEntity->Construct();
87 r = pHttpUrlEncodedEntity->AddParameter(L"name1", L"value1");
88 r = pHttpUrlEncodedEntity->AddParameter(L"name2", L"value2");
90 r = pRequest->SetEntity(*pHttpUrlEncodedEntity);
92 // Sends the HttpTransaction.
93 r = pTransaction->Submit();
99 class _OSP_EXPORT_ HttpUrlEncodedEntity
100 : public Tizen::Base::Object
106 * The object is not fully constructed after this constructor is called. @n
107 * For full construction, the Construct() method must be called right after calling this constructor.
111 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
113 HttpUrlEncodedEntity(void);
116 * This destructor overrides Tizen::Base::Object::~Object().
120 virtual ~HttpUrlEncodedEntity(void);
123 * Initializes this instance of %HttpUrlEncodedEntity.
127 * @return An error code
128 * @exception E_SUCCESS The method is successful.
129 * @exception E_SYSTEM A system error has occurred.
130 * @remarks The default content type is "application/x-www-form-urlencoded" and default character set is "ISO-8859-1".
132 result Construct(void);
135 * Initializes this instance of %HttpUrlEncodedEntity with the specified parameters.
139 * @return An error code
140 * @param[in] charset The character set of the entity
141 * @param[in] encoding The encoding scheme for the parameters
142 * @exception E_SUCCESS The method is successful.
143 * @exception E_SYSTEM A system error has occurred.
144 * @remarks The default content type is "application/x-www-form-urlencoded".
146 result Construct(const Tizen::Base::String& charset, const Tizen::Text::Encoding& encoding);
150 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
152 * @param[in] rhs An instance of %HttpUrlEncodedEntity
154 HttpUrlEncodedEntity(const HttpUrlEncodedEntity& rhs);
157 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
159 * @param[in] rhs An instance of %HttpUrlEncodedEntity
161 HttpUrlEncodedEntity& operator =(const HttpUrlEncodedEntity& rhs);
165 * Gets the length of the request content.
169 * @return The length of the content, @n
170 * else @c -1 if the content length is unknown
172 virtual long long GetContentLength(void) const;
175 * Gets the type of the request content.
179 * @return The type of the content
181 virtual Tizen::Base::String GetContentType(void) const;
184 * Adds the form data (name and value pairs) to %HttpUrlEncodedEntity.
188 * @return An error code
189 * @param[in] name The name of the urlencoded entity
190 * @param[in] value The value of the urlencoded entity
191 * @exception E_SUCCESS The method is successful.
192 * @exception E_INVALID_ARG A specified input parameter is invalid.
193 * @exception E_INVALID_ENCODING_RANGE The specified @c name or @c value contains code points that are outside the bounds of the specified @c encoding.
194 * @exception E_SYSTEM A system error has occurred.
196 result AddParameter(const Tizen::Base::String& name, const Tizen::Base::String& value);
200 * Checks whether the next data exists.
204 * @return @c true if the next data exists, @n
206 * @exception E_SUCCESS The method is successful.
207 * @exception E_INVALID_STATE The method invoked is invalid.
208 * @exception E_SYSTEM A system error has occurred.
209 * @remarks The specific error code can be accessed using the GetLastResult() method.
211 virtual bool HasNextData(void);
214 * Gets the next data.
218 * @return The buffer to read
219 * @param[in] recommendedSize The recommended size of the data to send
220 * @exception E_SUCCESS The method is successful.
221 * @exception E_INVALID_STATE The method invoked is invalid.
222 * @exception E_SYSTEM A system error has occurred.
223 * @remarks The specific error code can be accessed using the GetLastResult() method.
225 virtual Tizen::Base::ByteBuffer* GetNextDataN(int recommendedSize);
228 friend class _HttpUrlEncodedEntityImpl;
229 _HttpUrlEncodedEntityImpl* __pHttpUrlEncodedEntityImpl;
231 }; // HttpUrlEncodedEntity
233 } } } // Tizen::Net::Http
234 #endif // _FNET_HTTP_HTTP_URL_ENCODED_ENTITY_H_