当前位置: 首页>>代码示例>>C++>>正文


C++ HttpRequest::GetHeader方法代码示例

本文整理汇总了C++中HttpRequest::GetHeader方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpRequest::GetHeader方法的具体用法?C++ HttpRequest::GetHeader怎么用?C++ HttpRequest::GetHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpRequest的用法示例。


在下文中一共展示了HttpRequest::GetHeader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: hostAddr

HttpThread::HttpThread(std::string const & url,
                       downloader::IHttpThreadCallback & callback,
                       int64_t beg,
                       int64_t end,
                       int64_t size,
                       string const & pb)
  : m_callback(callback),
    m_begRange(beg), m_endRange(end),
    m_downloadedBytes(0), m_expectedSize(size),
    m_url(url), m_pb(pb),
    m_pSession(0),
    m_pTransaction(0)
{
  result r = E_SUCCESS;

  String * pProxyAddr = 0;
  String hostAddr(m_url.c_str());
  HttpHeader * header = 0;

  LOG(LDEBUG, ("Creating HttpSession", m_url));
  m_pSession = new HttpSession();
  r = m_pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, pProxyAddr, hostAddr, header);
  if (r != E_SUCCESS)
  {
    LOG(LERROR, ("HttpSession Construction error:", r));
    return;
  }

  // Open a new HttpTransaction.
  m_pTransaction = m_pSession->OpenTransactionN();
  if ((r = GetLastResult()) != E_SUCCESS)
  {
    LOG(LERROR, ("OpenTransactionN", GetLastResult()));
    return;
  }

  m_pTransaction->AddHttpTransactionListener(*this);
  m_pTransaction->SetHttpProgressListener(*this);

  HttpRequest * pRequest = m_pTransaction->GetRequest();
  pRequest->SetUri(m_url.c_str());

  HttpHeader * pHeader = pRequest->GetHeader();

  // use Range header only if we don't download whole file from start
  if (!(m_begRange == 0 && m_endRange < 0))
  {
    if (m_endRange > 0)
    {
      LOG(LDEBUG, (m_url, "downloading range [", m_begRange, ",", m_endRange, "]"));
      String range("bytes=");
      range.Append(m_begRange);
      range.Append('-');
      range.Append(m_endRange);
      pHeader->AddField(L"Range", range);
    }
    else
    {
      LOG(LDEBUG, (m_url, "resuming download from position", m_begRange));
      String range("bytes=");
      range.Append(m_begRange);
      range.Append('-');
      pHeader->AddField("Range", range);
    }
  }

  // set user-agent with unique client id only for mapswithme requests
  if (m_url.find("mapswithme.com") != string::npos)
  {
    static string const uid = GetPlatform().UniqueClientId();
    pHeader->AddField("User-Agent", uid.c_str());
  }

  if (m_pb.empty())
  {
    pRequest->SetMethod(NET_HTTP_METHOD_GET);
  }
  else
  {
    pRequest->SetMethod(NET_HTTP_METHOD_POST);
    pHeader->AddField("Content-Type", "application/json");
    int64_t const sz = m_pb.size();
    String length;
    length.Append(sz);
    pHeader->AddField("Content-Length", length);
    ByteBuffer body;
    body.Construct((const byte *)m_pb.c_str(), 0, sz, sz);
    pRequest->WriteBody(body);
  }
  LOG(LDEBUG, ("Connecting to", m_url, "[", m_begRange, ",", m_endRange, "]", "size=", m_expectedSize));
  m_pTransaction->Submit();
}
开发者ID:DINKIN,项目名称:omim,代码行数:92,代码来源:http_thread_tizen.cpp


注:本文中的HttpRequest::GetHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。