我用CHttpFile测试 好像还可以, 没有长时间测试比对数据 你可以试试看
DWORD HttpRead(LPCTSTR pstrURL, CString &szReturn)
{
DWORD dwError = 0;
//初始化Socket
do
{
if(!AfxSocketInit())
{
dwError = ERROR_INTERNET_TCPIP_NOT_INSTALLED;
ASSERT(FALSE);
break;
}
CInternetSession session;
CHttpFile* pFile = NULL;
try
{
if((pFile = (CHttpFile*)session.OpenURL(pstrURL)) != NULL)
{
DWORD dwRet = 0;
pFile->QueryInfoStatusCode(dwRet);
while (dwRet == HTTP_STATUS_OK)
{
char szBuff[1025];
memset(szBuff, 0, sizeof(szBuff));
UINT nRead = pFile->Read(szBuff, 1024);
if(nRead > 0)
{
szReturn += szBuff;
}
else
{
break;
}
}
pFile->Close();
}
}
catch (CInternetException* pEx)
{
//catch errors from WinInet
dwError = pEx->m_dwError;
#ifdef _DEBUG
pEx->ReportError();
#endif
pEx->Delete();
} //结束清理
if(pFile){ delete pFile; pFile = NULL; }
session.Close();
}while(0);
return dwError;
} TRACE(_T("测试\n\n")); for(int i=0; i<100; i++)
{
{
CString strEcho;
DWORD dwStartTick = GetTickCount(); DWORD dwErr = HttpRead(_T("https://bter.com/api/1/ticker/btc_cny"), strEcho); strEcho.Remove(_T('\r')); strEcho.Remove(_T('\n'));
CString dbgOut;
dbgOut.Format(_T("err(%lu) Echo=\"%s\", tick=%lu\r\n"),
dwErr, strEcho, GetTickCount() - dwStartTick);
OutputDebugString(dbgOut);
}
{
CString strEcho;
DWORD dwStartTick = GetTickCount(); DWORD dwErr = HttpRead(_T("https://bter.com/api/1/depth/btc_cny\n"), strEcho); strEcho.Remove(_T('\r')); strEcho.Remove(_T('\n'));
CString dbgOut;
dbgOut.Format(_T("err(%lu) Echo=\"%s\", tick=%lu\r\n"),
dwErr, strEcho, GetTickCount() - dwStartTick);
OutputDebugString(dbgOut);
}
}输出中间数据长就不贴了
err(0) Echo="{"result":"true","last": ……}0", tick=390
err(0) Echo="{"result":"true","asks": ……}0", tick=436
DWORD HttpRead(LPCTSTR pstrURL, CString &szReturn)
{
DWORD dwError = 0;
//初始化Socket
do
{
if(!AfxSocketInit())
{
dwError = ERROR_INTERNET_TCPIP_NOT_INSTALLED;
ASSERT(FALSE);
break;
}
CInternetSession session;
CHttpFile* pFile = NULL;
try
{
if((pFile = (CHttpFile*)session.OpenURL(pstrURL)) != NULL)
{
DWORD dwRet = 0;
pFile->QueryInfoStatusCode(dwRet);
while (dwRet == HTTP_STATUS_OK)
{
char szBuff[1025];
memset(szBuff, 0, sizeof(szBuff));
UINT nRead = pFile->Read(szBuff, 1024);
if(nRead > 0)
{
szReturn += szBuff;
}
else
{
break;
}
}
pFile->Close();
}
}
catch (CInternetException* pEx)
{
//catch errors from WinInet
dwError = pEx->m_dwError;
#ifdef _DEBUG
pEx->ReportError();
#endif
pEx->Delete();
} //结束清理
if(pFile){ delete pFile; pFile = NULL; }
session.Close();
}while(0);
return dwError;
} TRACE(_T("测试\n\n")); for(int i=0; i<100; i++)
{
{
CString strEcho;
DWORD dwStartTick = GetTickCount(); DWORD dwErr = HttpRead(_T("https://bter.com/api/1/ticker/btc_cny"), strEcho); strEcho.Remove(_T('\r')); strEcho.Remove(_T('\n'));
CString dbgOut;
dbgOut.Format(_T("err(%lu) Echo=\"%s\", tick=%lu\r\n"),
dwErr, strEcho, GetTickCount() - dwStartTick);
OutputDebugString(dbgOut);
}
{
CString strEcho;
DWORD dwStartTick = GetTickCount(); DWORD dwErr = HttpRead(_T("https://bter.com/api/1/depth/btc_cny\n"), strEcho); strEcho.Remove(_T('\r')); strEcho.Remove(_T('\n'));
CString dbgOut;
dbgOut.Format(_T("err(%lu) Echo=\"%s\", tick=%lu\r\n"),
dwErr, strEcho, GetTickCount() - dwStartTick);
OutputDebugString(dbgOut);
}
}输出中间数据长就不贴了
err(0) Echo="{"result":"true","last": ……}0", tick=390
err(0) Echo="{"result":"true","asks": ……}0", tick=436
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货