|
#1
|
|||
|
|||
|
GetHttpConnection
Hello,
I have the following code ... CString GE_URL ( "www.google.com"); CString GE_File( "test.txt" ); DisplayHttpPage( GE_URL, GE_File ); ... static void DisplayHttpPage(LPCTSTR pszServerName, LPCTSTR pszFileName) { CInternetSession session(_T("Ami's Session")); session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 1000); session.SetOption(INTERNET_OPTION_CONNECT_RETRIES, 3); try { CString strServerName; INTERNET_PORT nPort = 80; DWORD dwRet = 0; CString username = "..."; CString password = "..."; CHttpConnection* pServer = session.GetHttpConnection(pszServerName, 1, nPort, username, password); CHttpFile* pFile = pServer->OpenRequest(_T("GET"),pszServerName,NULL,1,NULL,NULL,INTERNET_FLAG_KEEP_CONNECTION); pFile->SendRequest(); // throws "URL not found" exception here... pFile->QueryInfoStatusCode(dwRet); cout << "dwRet = [" << dwRet << "]\n"; if (dwRet == HTTP_STATUS_OK) { CHAR szBuff[1024]; while (pFile->Read(szBuff, 1024) > 0) { std::cout << "szBuff = [" << szBuff << "]\n"; } } delete pFile; delete pServer; } catch (CInternetException* pEx) { //catch errors from WinInet TCHAR pszError[64]; pEx->GetErrorMessage(pszError, 64); std::cout << "Error : [" << pszError << "]\n"; } session.Close(); } I am always getting dwRet to be 502. Can someone please advise why this is the case and what this error means and how to resolve it ? Many thanks. |
|
#2
|
|||
|
|||
|
HTTP_STATUS_BAD_GATEWAY
according to google, ^^^^^^^ is your error code (502). How to fix that, I do not know. |
|
#3
|
|||
|
|||
|
Thanks for the reply Jonnin.
Does the code look ok to you ? Many thanks for your help. |
|
#4
|
|||
|
|||
|
The code looks legal, but its using API calls that I do not have experience with (I use low level UDP code for what networking we do, or just bytes directly sent to the radios sometimes). I have no idea beyond what google had to say, which implies the code is ok but the parameters are wrong (but thats just a guess!).
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|