Languages

Menu
Sites
Language
Getting partial JSon response for HTTP GET request
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");
 
}
}
 

 

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

2 Replies
wil smith
Can you share a sample project here, probably somebody can guide you with that.
Cuong Thai
@will smith: I have similar issue: it also print partial body. I tried
ByteBuffer* pBuffer = pHttpResponse->ReadBodyN();
byte* tempBody = new byte[availableBodyLen];
pBuffer->GetArray(tempBody, 0, availableBodyLen);
AppLogDebug("Body: %s", (char *)tempBody);
It printed partial body. So I use buffer to get body and it works
ByteBuffer* pBuffer = pHttpResponse->ReadBodyN();
int bodysize = availableBodyLen;
while (bodysize > 512) {
  byte* tempBody = new byte[512];
  pBuffer->GetArray(tempBody, 0, 512);
  AppLogDebug("BodyBuff: %s", (char *)tempBody);
  bodysize -= 512;
  delete [] tempBody;
}
if (bodysize > 0) {
  byte* tempBody = new byte[bodysize+1];
  pBuffer->GetArray(tempBody, 0, bodysize);
  AppLogDebug("BodyRemain: %s", (char *)tempBody);
  delete [] tempBody;
}