从一页读取的问题 [英] Problem For Read From One Page
问题描述
我的C ++代码有一个非常奇怪的问题.
我的代码的一部分连接到一个网站的特定页面,并读取一个数字(例如,数字45814).我的代码可以在所有服务器上正常工作,但是最近我在特定服务器上遇到了问题.从该页读取的数字显示为"458140"而不是"45814".我的意思是它在数字上加一个零.我的代码如下:
Hi,
I got very strange problem with my C++ code.
One section my code connect to specific page of one website and read one number(for example number 45814). My code working good with all servers but recently I got problem with specific server. When read number from this page shows number "458140" instead "45814". I mean it adds one zero to number. my code is as below:
char* __stdcall Get_Account_Number_FromWEB()
{
std::string strTopic = "get account from web";
//!!!! this is to be replaced with our request
const char * szPlimusRef = gpVar->m_strPlimusRef.c_str();
std::string strHttpReq = "http://www.example.com/1.htm"; // sample page
HINTERNET webHANDLE = InternetOpen(strTopic.c_str(), 0, "0", "0", 0);
HINTERNET webResult = InternetOpenUrlA(webHANDLE, strHttpReq.c_str(), "0", 0, -2080374528, 0);
if ( webResult )
{
char szwebBuffer[1024];
memset(szwebBuffer,0,sizeof(szwebBuffer));
DWORD dwBytes = sizeof(szwebBuffer);
DWORD dwBytesActual = 0;
BOOL bRead = InternetReadFile(webResult, szwebBuffer, dwBytes, &dwBytesActual);
InternetCloseHandle(webResult);
gpVar->m_strWEBDigest = (char*)szwebBuffer;
}
else
{
gpVar->m_strWEBDigest = "No internet connection";
}
InternetCloseHandle(webHANDLE);
return (char*)gpVar->m_strWEBDigest.c_str();
}
手动打开此页面时,我看到"45814",但读取此功能时显示"458140".
我用另一台服务器检查了这一切是否正常,但是只有一台服务器遇到了这个奇怪的问题.
谁能解决这个问题?
问候
When open this page manually I see "45814" but when this function read that shows "458140".
I checked this with different server all works correctly but only one server got this strange problem.
Can anybody solve this problem?
Regards,
推荐答案
检查已读取的字节(dwBytesActual
)并终止字符串:
Check the bytes readen (dwBytesActual
) and terminate the string:
szwebBuffer[dwBytesActual]=0;
问候.
这篇关于从一页读取的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!