Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > C++

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-28-2009, 01:43 PM
ami ami is offline
Registered User
 
Join Date: May 2004
Posts: 187
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.
Reply With Quote
  #2  
Old 10-28-2009, 03:18 PM
jonnin jonnin is offline
Senior Member
 
Join Date: Dec 2003
Posts: 3,008
HTTP_STATUS_BAD_GATEWAY

according to google, ^^^^^^^ is your error code (502). How to fix that, I do not know.
Reply With Quote
  #3  
Old 10-28-2009, 04:46 PM
ami ami is offline
Registered User
 
Join Date: May 2004
Posts: 187
Thanks for the reply Jonnin.

Does the code look ok to you ?

Many thanks for your help.
Reply With Quote
  #4  
Old 10-28-2009, 04:56 PM
jonnin jonnin is offline
Senior Member
 
Join Date: Dec 2003
Posts: 3,008
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!).
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 01:59 AM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.