使用以下代码作为参考,在 tizen 中,我们将响应作为数据块获取,正如您所说的 15559 字节是参考数据。所以你应该收集字节缓冲区数据,直到你得到整个数据。
Code description:
将字节缓冲区保留为类变量 ( here _pBuff
)
_hasData
是一个标志,一旦缓冲区有数据就设置(然后你需要附加数据)
一旦你得到整个数据清除_pbuff
void YourClass::OnTransactionReadyToRead(HttpSession& httpSession,
HttpTransaction& httpTransaction, int availableBodyLen) {
AppLog("Transaction Ready to Read : availableBodyLen %d", availableBodyLen);
try {
HttpResponse* pHttpResponse = null;
HttpHeader* pHttpHeader = null;
pHttpResponse = httpTransaction.GetResponse();
if (pHttpResponse->GetHttpStatusCode() == HTTP_STATUS_OK) {
bool _hasData = false;
if (!_pBuff) {
_pBuff = new ByteBuffer;
_pBuff->Construct(availableBodyLen);
}
else
{
_pBuff->ExpandCapacity(_pBuff->GetCapacity() + availableBodyLen);
_hasData = true;
}
pHttpHeader = pHttpResponse->GetHeader();
if(_hasData)
{
ByteBuffer* pBody = pHttpResponse->ReadBodyN();
// add to local store
byte* pByte = new byte[availableBodyLen];
pBody->GetArray(pByte,0,availableBodyLen);
_pBuff->SetPosition(_pBuff->GetCapacity() - availableBodyLen);
_pBuff->SetArray(pByte,0,availableBodyLen);
delete []pByte;
delete pBody;
}
else
_pBuff = pHttpResponse->ReadBodyN();
// Your Call || code
}
}