得到HTTP头协议后, 获取状态值和返回数据的大小。
void CClientEngine::MHFRunL(RHTTPTransaction aTransaction,
const THTTPEvent& aEvent)
{
switch (aEvent.iStatus)
{
case THTTPEvent::EGotResponseHeaders:
{
// Get HTTP status code from header (e.g. 200)
RHTTPResponse resp = aTransaction.Response();
TInt status = resp.StatusCode();
// Get status text (e.g. "OK")
TBuf<KStatustextBufferSize> statusText;
statusText.Copy(resp.StatusText().DesC());
//从消息头中获取文件大小
RHTTPHeaders headers = resp.GetHeaderCollection();
THTTPHdrVal aHeaderValue;
TRAPD(Err,
RStringPool string_pool = iSession.StringPool ();
RStringF contLength = string_pool.OpenFStringL (_L8("Content-Length") );
headers.GetField (contLength, 0, aHeaderValue );
contLength.Close ();
);
TInt nTotalSize = aHeaderValue.Int();
TBuf<32> bTotalSize;
bTotalSize.AppendNum(nTotalSize);
break;
}
}
}
获取HTTP头协议中状态值和数据大小
最新推荐文章于 2021-03-24 07:41:35 发布