Jump to content
  • Advertisement
Sign in to follow this  
steg

Wininet and proxy server - URGENT

This topic is 5456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi friends, I have written some code to download files from a webserver using wininet. Now my problem is that a customer using this code goes through a proxy server, my code doesn't work for this, it only works with direct connection to the internet. Does anybody know how I can make it download a file by going via a proxy server ? I've included the function I use below, but doesn't work for proxy ?
BOOL CWebForm::ProxyGetFile(CString strFile, CString strServerURL, CString strURL, CString strProxy)
{
	m_dwFileLen = 0;
	HINTERNET hINet, hConnection, hData;
	CHAR buffer[1000] ; 
	CString m_strContents ;
	DWORD dwRead, dwFlags, dwStatus ;
	
	strServerURL = strServerURL.Mid( strServerURL.Find("//") + 2 );
	
	if( strProxy.IsEmpty() )
		hINet = InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 );
	else
		hINet = InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_PROXY, strProxy, NULL, 0 );
	
	if ( !hINet )
	{
		AfxMessageBox("InternetOpen Failed");
		return false;
	}
	
	try 
	{
		//strServerURL = "192.168.16.11";
		hConnection = InternetConnect( hINet, strServerURL, 80, " "," ", INTERNET_SERVICE_HTTP, 0, 0 );
		
		
		if ( !hConnection )
		{
			InternetCloseHandle(hINet);
			return false;
		}
		
		// Get data
		hData = HttpOpenRequest( hConnection, "GET", strURL, NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0 );
		
		if ( !hData )
		{
			InternetCloseHandle(hConnection);
			InternetCloseHandle(hINet);
			return false;
		}
		
		HttpSendRequest( hData, NULL, 0, NULL, 0);
		
		CFile Storefile( strFile, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary );
		while ( InternetReadFile( hData, buffer, 255, &dwRead ))
		{
			if ( dwRead == 0 )
				break;
			buffer[dwRead] = 0;
			m_strContents += buffer;
			Storefile.Write(buffer, dwRead);			
			m_dwFileLen += dwRead;
		}
		
		if(m_pHttpbuff)
			delete[] m_pHttpbuff;
		
		m_pHttpbuff = new char[m_dwFileLen];
		memset( m_pHttpbuff, '\0', m_dwFileLen );
		memcpy( m_pHttpbuff, m_strContents.GetBuffer(m_strContents.GetLength()), m_dwFileLen );
		Storefile.Close();
		
	} 
	
	catch( CInternetException* e)
	{
		AfxMessageBox("error");
		e->ReportError();
		e->Delete();
		return false;
	}
	
	InternetCloseHandle(hConnection);
	InternetCloseHandle(hINet);
	InternetCloseHandle(hData);	

	return true;
}


Any help is much appreciated Steve

Share this post


Link to post
Share on other sites
Advertisement
i'm not sure it's your problem but i'm experienced to work with proxies and in most case you must authenticate the proxy , given a user password account for setting up the right privileges.

Share this post


Link to post
Share on other sites
Thanks nini,

My problem is detecting that the user goes through a proxy and getting the proxy settings. Would I need to ask the user for these ?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!