Listing 8
void GetMap(HINTERNET hSession, TCHAR* szLat, TCHAR* szLong)
{
LPTSTR AcceptTypes[2] = {TEXT("text/xml"), NULL};
DWORD dwFlags = INTERNET_FLAG_RELOAD |
INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_KEEP_CONNECTION;
HINTERNET hRequest = HttpOpenRequest(hSession, _T("POST"),
_T("/Render-30/RenderService.asmx"), HTTP_VERSION,
NULL, (LPCTSTR*)AcceptTypes, dwFlags, 0);
if (hRequest)
{
wcout << _T("Opened Request for WS and got valid handle") << endl;
TCHAR szSoapAction[256];
_tcscpy( szSoapAction,_T("Content-Type:text/xml;charset=utf-8\n") );
_tcscat( szSoapAction, _T("SOAPAction: \"") );
_tcscat( szSoapAction, _T("http://s.mappoint.net/mappoint-30/GetMap") );
_tcscat( szSoapAction , _T("\"\0") );
TCHAR szSoap[1024];
BuildGetMapSoapRequest(szLat, szLong, szSoap);
DWORD dwSoapSize = _tcslen(szSoap);
CHAR* szSoapRequestA = new CHAR[dwSoapSize + 1];
DWORD dwSize = WideCharToMultiByte (CP_ACP, 0, szSoap,
-1, szSoapRequestA, 0, NULL, NULL);
WideCharToMultiByte (CP_ACP, 0, szSoap, -1,
szSoapRequestA, dwSize, NULL, NULL);
DWORD dwError, dwStatus, dwErrorCode;
DWORD dwStatusSize = sizeof(dwStatus);
BOOL bSent = HttpSendRequest(hRequest, szSoapAction,
_tcslen(szSoapAction), szSoapRequestA, strlen(szSoapRequestA) );
if ( bSent )
{
CHAR* lpBufferA = new CHAR[32000];
DWORD dwcBuffer;
if (!InternetReadFile (hRequest, (LPVOID)lpBufferA, 32000,
&dwcBuffer))
{
wcout << _T("Failed to read response") << endl;
}
else{
CHAR* szResponse = new CHAR[dwcBuffer + 1];
strncpy(szResponse,lpBufferA, dwcBuffer);
wcout << _T("Response") << endl << szResponse << endl;
delete [] szResponse;
}
delete [] lpBufferA;
}
else
{
DWORD dwErr = GetLastError();
wcout << _T("Send Request Failed. Error:") << dwErr << endl;
}
InternetCloseHandle(hRequest);
}
}