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 FNetHttpHttpStringEntity.h
20 * @brief This is the header file for the %HttpStringEntity class.
22 * This header file contains the declarations of the %HttpStringEntity class.
25 #ifndef _FNET_HTTP_HTTP_STRING_ENTITY_H_
26 #define _FNET_HTTP_HTTP_STRING_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 _HttpStringEntityImpl;
47 * @class HttpStringEntity
48 * @brief This class represents a http body for the text content.
52 * The %HttpStringEntity class represents a http body for the text content.
54 * The following example demonstrates how to use the %HttpStringEntity class to send the content for text to the server using this class.
61 using namespace Tizen::Base;
62 using namespace Tizen::Net::Http;
65 TestHttpStringEntity(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 HttpStringEntity* pHttpStringEntity = new HttpStringEntity();
85 pHttpStringEntity->Construct(L"test content body");
87 r = pRequest->SetEntity(*pHttpStringEntity);
89 // Sends the HttpTransaction.
90 r = pTransaction->Submit();
96 class _OSP_EXPORT_ HttpStringEntity
97 : public Tizen::Base::Object
103 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
107 * @remarks After creating an instance of this class, the Construct() method
108 * must be called explicitly to initialize this instance.
110 HttpStringEntity(void);
113 * This destructor overrides Tizen::Base::Object::~Object().
117 virtual ~HttpStringEntity(void);
120 * Initializes this instance of %HttpStringEntity with the default content type and character set.
124 * @return An error code
125 * @param[in] text The text of the body
126 * @exception E_SUCCESS The method is successful.
127 * @exception E_INVALID_ENCODING_RANGE The specified @c text contains code points that are outside the bounds of the default encoding standard ("ISO-8859-1").
128 * @exception E_SYSTEM A system error has occurred.
129 * @remarks The default content type is "text/plain" and default charset is "ISO-8859-1".
131 result Construct(const Tizen::Base::String& text);
134 * Initializes this instance of %HttpStringEntity with the specified parameters.
138 * @return An error code
139 * @param[in] text The text of the body
140 * @param[in] contentType The content type of @c text
141 * @param[in] charset The character set of @c text
142 * @param[in] encoding An encoding scheme for the specified @c text
143 * @exception E_SUCCESS The method is successful.
144 * @exception E_INVALID_ARG A specified input parameter is invalid.
145 * @exception E_INVALID_ENCODING_RANGE The specified @c text contains code points that are outside the bounds of @c encoding.
146 * @exception E_SYSTEM A system error has occurred.
148 result Construct(const Tizen::Base::String& text, const Tizen::Base::String& contentType, const Tizen::Base::String& charset, const Tizen::Text::Encoding& encoding);
153 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
155 * @param[in] rhs An instance of %HttpStringEntity
157 HttpStringEntity(const HttpStringEntity& rhs);
160 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
162 * @param[in] rhs An instance of %HttpStringEntity
164 HttpStringEntity& operator =(const HttpStringEntity& rhs);
168 * Gets the length of the request content.
172 * @return The length of the content, @n
173 * else @c -1 if the content length is unknown
175 virtual long long GetContentLength(void) const;
178 * Gets the type of the request content.
182 * @return The type of the content
184 virtual Tizen::Base::String GetContentType(void) const;
188 * Checks whether the next data exists.
192 * @return @c true if the next data exists, @n
194 * @exception E_SUCCESS The method is successful.
195 * @exception E_INVALID_STATE The method invoked is invalid.
196 * @exception E_SYSTEM A system error has occurred.
197 * @remarks The specific error code can be accessed using the GetLastResult() method.
199 virtual bool HasNextData(void);
202 * Gets the next data.
206 * @return The buffer to be read
207 * @param[in] recommendedSize The recommended size of the data to send
208 * @exception E_SUCCESS The method is successful.
209 * @exception E_INVALID_STATE The method invoked is invalid.
210 * @exception E_SYSTEM A system error has occurred.
211 * @remarks The specific error code can be accessed using the GetLastResult() method.
213 virtual Tizen::Base::ByteBuffer* GetNextDataN(int recommendedSize);
216 friend class _HttpStringEntityImpl;
217 _HttpStringEntityImpl* __pHttpStringEntityImpl;
219 }; // HttpStringEntity
221 } } } // Tizen::Net::Http
222 #endif // _FNET_HTTP_HTTP_STRING_ENTITY_H_