We are making a GET request for wordpress api ( :http://developer.wordpress.com/docs/api/1/get/freshly-pressed/).This api returns a json response of 10 freshly pressed posts .Each post consists of text as well as image data.We tested this api on desktop browser and the response data size is nearly 45-50 kb.
However, on Tizen simulator as well as on device we are getting data of only 2 posts.The callback function OnTransactionReadyToRead gets called 6 to 7 times and each time we receive certain chunk of data.However , execution suddenly goes to OnTransactionComplete callback function.
We tested one more api where the response size is small and in that case we received full proper response.
What changes need to be done to receive full response of this api?
void
BloggPressApiInterface::OnTransactionReadyToRead(HttpSession& httpSession, HttpTransaction& httpTransaction, int availableBodyLen)
{
HttpResponse* pHttpResponse = httpTransaction.GetResponse();
int code = pHttpResponse->GetHttpStatusCode();
if (pHttpResponse->GetHttpStatusCode() == HTTP_STATUS_OK)
{
//AppLogDebug("$$ HTTP Response Pranali");
HttpHeader* pHttpHeader = null;
//try {
if(!__bAccessTokenObtained)
{
pHttpHeader = pHttpResponse->GetHeader();
}
else
{
ByteBuffer* pBuffer = null;
//try {
pBuffer = pHttpResponse->ReadBodyN();
Tizen::Text::Encoding* pEnc = Tizen::Text::Encoding::GetEncodingN(L"ISO-8859-2");
String decodedStr;
pEnc->GetString(*pBuffer, decodedStr);
__strActualFreshlyPresseddata.Append(decodedStr);
AppLogDebug("&&Response %ls",decodedStr.GetPointer());
}
if (pHttpHeader != null)
{
String* tempHeaderString = pHttpHeader->GetRawHeaderN();
ByteBuffer* pBuffer = null;
try {
pBuffer = pHttpResponse->ReadBodyN();
} catch (...) {
}
//
Tizen::Text::Encoding* pEnc = Tizen::Text::Encoding::GetEncodingN(L"ISO-8859-2");
String decodedStr;
pEnc->GetString(*pBuffer, decodedStr);
IJsonValue* pValue2 = JsonParser::ParseN(*pBuffer);
IJsonValue* pValueAccessToken = null;
JsonString *pKeyNameAccessToken = new JsonString("access_token");
if( pValue2 == null )
{
}
else
{
// Uses the pValue to know what is the type
if( pValue2->GetType() == JSON_TYPE_OBJECT )
{
JsonObject* pJsonObj = static_cast<JsonObject*>(pValue2);//use pJsonObj to access key-value pairs
pJsonObj->GetValue(pKeyNameAccessToken,pValueAccessToken);
delete pKeyNameAccessToken;
if(pValueAccessToken != null)
{
if( pValueAccessToken->GetType() == JSON_TYPE_STRING )
{
JsonString* pAccessToken = static_cast<JsonString*>(pValueAccessToken);
Tizen::Base::String str(L"");
str.Append(*pAccessToken);
//AppLogDebug(" ++ Access Token Value: ++ %ls",str.GetPointer());
__pHttpSession = null;
if(!__bAccessTokenObtained)
{
__bAccessTokenObtained = true;
//AppLogDebug("Request sent*****************************************");
this->RequestHttpGet(L"http://public-api.wordpress.com/rest/v1/freshly-pressed/", str);
}
}
}
pJsonObj->RemoveAll(true);
}
}
delete tempHeaderString;
delete pBuffer;
}
}
else
{
ByteBuffer* pBuffer = pHttpResponse->ReadBodyN();
String text(L"Read Body Length: ");
Tizen::Text::Encoding* pEnc = Tizen::Text::Encoding::GetEncodingN(L"ISO-8859-2");
String decodedStr;
pEnc->GetString(*pBuffer, decodedStr);
AppLogDebug("Response body: %ls",decodedStr.GetPointer());
AppLogDebug("400");
}
}