views:

20

answers:

0

I write a temp http protocol and the Code is as follow, it works well for web pages navigating, but cannot for file download, such as http://**/111.zip . How to modify the code ? Envrionment: .Net 2.0, VS2008, C#

public void Start(string szURL, IInternetProtocolSink Sink, IInternetBindInfo pOIBindInfo, uint grfPI, uint dwReserved)
        {
            try
            {
                IServiceProvider Provider = (IServiceProvider)Sink;
                object obj_Negotiate = new object();
                Provider.QueryService(ref Guids.IID_IHttpNegotiate, ref Guids.IID_IHttpNegotiate, out obj_Negotiate);
                IHttpNegotiate Negotiate = (IHttpNegotiate)obj_Negotiate;
                string strRequestHeaders;
                Negotiate.BeginningTransaction(szURL, string.Empty, 0, out strRequestHeaders);
                BINDINFO BindInfo = GetBindInfo(pOIBindInfo);
                String RawPostData = GetPostData(BindInfo, szURL);
                HttpWebResponse HttpResp = GetHttpWebResponse(szURL, RawPostData, strRequestHeaders);
                uint RespCode = (uint)HttpResp.StatusCode;
                using (Stream RespStream = HttpResp.GetResponseStream())
                {
                    byte[] rgb = new byte[1024];
                    int cb;
                    while ((cb = RespStream.Read(rgb, 0, rgb.Length)) > 0)
                    {
                        MemStream.Write(rgb, 0, cb);
                    }
                }
                MemStream.Position = 0;
                String ContentType = HttpResp.GetResponseHeader("Content-Type");
                string StrResponseHeaders = HttpResp.Headers.ToString();
                string strNewResponseHeaders;
                Negotiate.OnResponse(RespCode, StrResponseHeaders, strRequestHeaders, out strNewResponseHeaders);
                Sink.ReportData(BSCF.BSCF_FIRSTDATANOTIFICATION | BSCF.BSCF_LASTDATANOTIFICATION | BSCF.BSCF_DATAFULLYAVAILABLE, (uint)MemStream.Length, (uint)MemStream.Length);

                if (!String.IsNullOrEmpty(ContentType))
                {
                    Sink.ReportProgress((uint)BINDSTATUS.BINDSTATUS_MIMETYPEAVAILABLE, ContentType);
                }
                Sink.ReportResult(0, 0, null);
                HttpResp.Close();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }