Httpresponse超过了Tizen中的缓冲区大小

时间:2013-11-14 16:52:09

标签: c++ httpresponse bytebuffer tizen tizen-native-app

我正在尝试解析ByteBuffer对象中包含的XML数据,该对象是使用类似于以下ReadBodyN()的代码获得的。如果Httprequest被赋予一个小的XML页面,ReadBodyN()和解析工作正常。但是对于执行ReadBodyN()后包含超过50k个字符的大型XML页面,ByteBuffer对象中只有15559个字符可用。如何将整个XML放入bytebuffer?

 HttpResponse* pResponse = httpTransaction.GetResponse();
 if (pResponse->GetHttpStatusCode() == HTTP_STATUS_OK)
 {
     ByteBuffer* pBody = null;
     pBody = pResponse->ReadBodyN();
 }

1 个答案:

答案 0 :(得分:2)

使用以下代码作为参考,在tizen中我们将响应作为数据块,正如您所说的15559字节是参考数据。因此,您应该收集bytebuffer数据,直到获得整个数据。

Code description:将bytebuffer保持为类变量(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
 }
 }