本文介绍了vc ++ UrlDownloadToFile在密码保护的代理中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行UrlDownloadToFile()

Hi I am trying to run UrlDownloadToFile()

CBSCallbackImplPX callback;
::URLDownloadToFileA(NULL, "http://www.codeproject.com/KB/system/keyboard.aspx" ,"c:\\test\\a.html",NULL,&callback);



哪里



Where

class CBSCallbackImplPX : public IBindStatusCallback 



即使使用proxy,它也可以正常工作,因为它使用IE的凭据.

但是今天,当我在受密码保护的代理下尝试相同的代码时,它会返回



It is working fine even in proxy.as it uses IE''s credential.

But today when I am trying the same code under password protected proxy it is returning

E_ACCESSDENIED

.

我研究了此链接
http://www.ureader.com/msg/1510234.aspx [ ^ ]

并了解了

.

I studied this link
http://www.ureader.com/msg/1510234.aspx[^]

and came to know about

IAuthenticate

接口.

但无法实现.

以下是我的回拨代码

Interface.

but not able to implement.

below is my call back code

class CBSCallbackImplPX : public IBindStatusCallback //,IServiceProvider,TIAuthenticate
{
public:
  CBSCallbackImplPX();
  ~CBSCallbackImplPX();
//TIAuthenticate  class taken from http://www.ureader.com/msg/1510234.aspx
//TIAuthenticate myAuthenticate;

 CString m_csData; 
 DWORD m_dwSize;
 int nTitmeOut;
  // IUnknown methods
  STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject);
  STDMETHOD_(ULONG, AddRef)();
  STDMETHOD_(ULONG, Release)();

  // IBindStatusCallback methods
  STDMETHOD(OnStartBinding)(DWORD, IBinding *);
  STDMETHOD(GetPriority)(LONG *);
  STDMETHOD(OnLowResource)(DWORD);
  STDMETHOD(OnProgress)(ULONG ulProgress,
    ULONG ulProgressMax,
    ULONG ulStatusCode,
    LPCWSTR szStatusText);
  STDMETHOD(OnStopBinding)(HRESULT, LPCWSTR);
  STDMETHOD(GetBindInfo)(DWORD *, BINDINFO *);
  STDMETHOD(OnDataAvailable)(DWORD, DWORD, FORMATETC *, STGMEDIUM *);
  STDMETHOD(OnObjectAvailable)(REFIID, IUnknown *);

//   HRESULT STDMETHODCALLTYPE QueryService( REFGUID guidService, REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject) ;
protected:
  ULONG m_ulObjRefCount;
  clock_t m_startDownload,m_endDownload;

};













// BSCallbackImpl.cpp: implementation of the CBSCallbackImplPX class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "BSCallbackImplPX.h"


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//--------------------------------------------------------------------
CBSCallbackImplPX::CBSCallbackImplPX()
{
	nTitmeOut=10;
	m_ulObjRefCount = 1;
	m_csData="";
	m_dwSize=0;
	m_startDownload,m_endDownload=0;
}


//--------------------------------------------------------------------
CBSCallbackImplPX::~CBSCallbackImplPX()
{
}


//--------------------------------------------------------------------
// IUnknown
STDMETHODIMP CBSCallbackImplPX::QueryInterface(REFIID riid, void **ppvObject)
{
	
	*ppvObject = NULL;

	// IUnknown
	if (::IsEqualIID(riid, __uuidof(IUnknown)))
	{
		//TRACE(_T("IUnknown::QueryInterface(IUnknown)\n"));

		*ppvObject = this;
	}
	// IBindStatusCallback
	else if (::IsEqualIID(riid, __uuidof(IAuthenticate)))
	{
		//TRACE(_T("IUnknown::QueryInterface(IBindStatusCallback)\n"));

		AfxMessageBox("found something");//can I implement the callback here??
		//*ppvObject = /*static_cast(*/this/*)*/;
	}

		if (::IsEqualIID(riid, __uuidof(IUnknown)))
		{}
	if (*ppvObject)
	{
		this->AddRef();
		/*(*reinterpret_cast(ppvObject))->AddRef();*/  //Ram:As unicode casting.

		return S_OK;
	}

	return E_NOINTERFACE;
}





//--------------------------------------------------------------------
STDMETHODIMP_(ULONG) CBSCallbackImplPX::AddRef()
{
	//TRACE(_T("IUnknown::AddRef\n"));

	return ++m_ulObjRefCount;
}


//--------------------------------------------------------------------
STDMETHODIMP_(ULONG) CBSCallbackImplPX::Release()
{
	//TRACE(_T("IUnknown::Release\n"));

	return --m_ulObjRefCount;
}


//--------------------------------------------------------------------
// IBindStatusCallback
STDMETHODIMP CBSCallbackImplPX::OnStartBinding(DWORD d, IBinding *ib)
{
	//ib=&myAuthenticate;
	//TRACE(_T("IBindStatusCallback::OnStartBinding\n"));
	m_startDownload=clock();
	return S_OK;
}


//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::GetPriority(LONG *)
{
	//TRACE(_T("IBindStatusCallback::GetPriority\n"));

	return E_NOTIMPL;
}


//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::OnLowResource(DWORD)
{
	//TRACE(_T("IBindStatusCallback::OnLowResource\n"));

	return S_OK;
}


//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::OnProgress(ULONG ulProgress,
										   ULONG ulProgressMax,
										   ULONG ulStatusCode,
										   LPCWSTR szStatusText)
{
	m_endDownload=clock();
	int nTimeTakenForThisDownload=0;
	nTimeTakenForThisDownload=((int)( m_endDownload - m_startDownload)/CLOCKS_PER_SEC) ;
	if(nTimeTakenForThisDownload>=nTitmeOut)
	{
		////CMTLog::WriteLogMT("Download cancelled by client");
		return E_ABORT;  // Download canceled by the client
	}
	return S_OK;
}


//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::OnStopBinding(HRESULT, LPCWSTR)
{
	//TRACE(_T("IBindStatusCallback::OnStopBinding\n"));

	return S_OK;
}


//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::GetBindInfo(DWORD *d, BINDINFO * b)
{
	//b->pUnk = &myAuthenticate;
	//TRACE(_T("IBindStatusCallback::GetBindInfo\n"));
	return S_OK;
}


//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::OnDataAvailable(DWORD dww, DWORD dwSize,
												FORMATETC *fww, STGMEDIUM *stgmed )
{
	//TRACE(_T("IBindStatusCallback::OnDataAvailable %ld\n"), dwSize );
//	//CMTLog::WriteLogMT2("IBindStatusCallback::OnDataAvailable %ld ",dwSize);
	if ( stgmed ) {
		if ( stgmed->pstm ) {

			ULONG bytesRead = 0;

			dwSize=dwSize-m_dwSize;

			BYTE *data = new BYTE[ dwSize + 1 ];
			//*data=(char)NULL;
			HRESULT hRes = stgmed->pstm->Read( data, dwSize, &bytesRead );
			data[dwSize] = ''\0'';

			m_dwSize+=bytesRead;
			m_csData +=(char *)data;

			/*
			BYTE *data = (BYTE*)m_csData.GetBuffer( m_csData.GetLength() + dwSize + 1 );
			HRESULT hRes = stgmed->pstm->Read( data, dwSize, &bytesRead );
			m_dwSize+=bytesRead;
			m_csData.ReleaseBuffer();
			*/

			delete data;
			data=NULL;

			return hRes;
		}
	}

	return S_OK;
}


//--------------------------------------------------------------------
STDMETHODIMP CBSCallbackImplPX::OnObjectAvailable(REFIID, IUnknown *)
{
	//TRACE(_T("IBindStatusCallback::OnObjectAvailable\n"));

	return S_OK;
}


//--------------------------------------------------------------------



请帮助:(



please help :(

推荐答案

URLDownloadToFile(NULL,"http://prodex:[email protected]/KB/system/keyboard.aspx","c:\\test\\a.html",NULL,NULL);


它的工作:)

仍然无法通过回调来完成.

请为此发送一些代码段.


its working :)

still not able to do through callback.

please send some code snippet for that.


这篇关于vc ++ UrlDownloadToFile在密码保护的代理中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 06:30