John
2004-07-29 20:18:30 UTC
Hello,
I have a client/server based program that occasionally uses wininet to
post information. For some reason, some of our clients, particularly
those located far from our office (we have some that are
international) are sending duplicate posts almost simultaneously. Some
clients will post the same information 5-10 times within a second!
Also, it appears this problem is limited to Windows XP.
Here is the code I've been using to post information:
int PostInfo(LPCTSTR strResource, LPCTSTR strPostInfo, CString&
strResponse)
{
CInternetSession session();
CHttpConnection* pConnection = NULL;
CHttpFile* pFile = NULL;
try
{
CHttpConnection* pConnection =
session.GetHttpConnection(AD_SERVER_ADDR,AD_SERVER_PORT);
CHttpFile* pFile =
pConnection->OpenRequest(0,strResource,NULL,1,NULL,NULL,INTERNET_FLAG_DONT_CACHE
| INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_KEEP_CONNECTION |
INTERNET_FLAG_RELOAD);
CString strHeaders = _T("Content-Type:
application/x-www-form-urlencoded");
if (pFile->SendRequest(strHeaders,(LPVOID)strPostInfo,CString(strPostInfo).GetLength()))
{
DWORD dwStatus;
pFile->QueryInfoStatusCode(dwStatus);
if (HTTP_STATUS_OK == dwStatus)
{
char szBuffer[256];
DWORD dwRead = 0;
for(;;)
{
dwRead = pFile->Read(szBuffer,255);
szBuffer[dwRead] = 0;
strResponse += szBuffer;
if (dwRead ==0)
{
break;
}
}
}
else
{
pFile->Close();
delete pFile;
pConnection->Close();
delete pConnection;
session.Close();
return -1;
}
}
pFile->Close();
delete pFile;
pConnection->Close();
delete pConnection;
}
catch(CInternetException* e)
{
#ifdef _DEBUG
e->ReportError();
WriteDebug("Internet Exception thrown!\n");
#endif
e->Delete();
return -1;
}
if (pFile != NULL)
delete pFile;
if (pConnection != NULL)
delete pConnection;
session.Close();
return 0;
}
Can anyone see anything wrong with the above code?
Thanks very much for any help!
- John
I have a client/server based program that occasionally uses wininet to
post information. For some reason, some of our clients, particularly
those located far from our office (we have some that are
international) are sending duplicate posts almost simultaneously. Some
clients will post the same information 5-10 times within a second!
Also, it appears this problem is limited to Windows XP.
Here is the code I've been using to post information:
int PostInfo(LPCTSTR strResource, LPCTSTR strPostInfo, CString&
strResponse)
{
CInternetSession session();
CHttpConnection* pConnection = NULL;
CHttpFile* pFile = NULL;
try
{
CHttpConnection* pConnection =
session.GetHttpConnection(AD_SERVER_ADDR,AD_SERVER_PORT);
CHttpFile* pFile =
pConnection->OpenRequest(0,strResource,NULL,1,NULL,NULL,INTERNET_FLAG_DONT_CACHE
| INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_KEEP_CONNECTION |
INTERNET_FLAG_RELOAD);
CString strHeaders = _T("Content-Type:
application/x-www-form-urlencoded");
if (pFile->SendRequest(strHeaders,(LPVOID)strPostInfo,CString(strPostInfo).GetLength()))
{
DWORD dwStatus;
pFile->QueryInfoStatusCode(dwStatus);
if (HTTP_STATUS_OK == dwStatus)
{
char szBuffer[256];
DWORD dwRead = 0;
for(;;)
{
dwRead = pFile->Read(szBuffer,255);
szBuffer[dwRead] = 0;
strResponse += szBuffer;
if (dwRead ==0)
{
break;
}
}
}
else
{
pFile->Close();
delete pFile;
pConnection->Close();
delete pConnection;
session.Close();
return -1;
}
}
pFile->Close();
delete pFile;
pConnection->Close();
delete pConnection;
}
catch(CInternetException* e)
{
#ifdef _DEBUG
e->ReportError();
WriteDebug("Internet Exception thrown!\n");
#endif
e->Delete();
return -1;
}
if (pFile != NULL)
delete pFile;
if (pConnection != NULL)
delete pConnection;
session.Close();
return 0;
}
Can anyone see anything wrong with the above code?
Thanks very much for any help!
- John