【问题标题】:Httpresponse exceeds the buffer size in TizenHttpresponse 超出 Tizen 中的缓冲区大小
【发布时间】:2013-11-27 19:30:35
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    使用以下代码作为参考,在 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
     }
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-31
      • 2011-12-24
      • 1970-01-01
      • 2014-10-07
      • 1970-01-01
      • 2014-03-26
      相关资源
      最近更新 更多