c# - 有谁知道这个错误 : "Wrong Local header signature: 0x6D74683C"?

标签 c# windows-phone-7 download windows-phone-8 webrequest

以下代码用于下载 zip 文件并在手机上解压。

用于在 WP7 上工作的相同代码,我开始在 WP8 设备上测试,奇怪的事情发生了......现在它在 WP8 上工作但在 WP7 上了。

在 WP7 上它给出了一个错误:

Wrong Local header signature: 0x6D74683C

谁能告诉我这里出了什么问题?

观察结果(发布问题 2 天后)

我有一些观察....在这里详分割享(Image format)或(Excel format)

代码

using ICSharpCode.SharpZipLib.Zip;
using System;
using System.Diagnostics;
using System.IO;
using System.IO.IsolatedStorage;
using System.Net;

namespace iq_main.Network
{

    public class IQ_Download
    {
        private string zipFilePassword = String.Empty;
        private string fileNameToBeStoredAs = String.Empty;
        private string urlToBeDownloaded = String.Empty;
        private HttpWebResponse response;

        public void Download(string _urlToBeDownloaded = GlobalConstants.DownloadLanguageConfigurationUrl, string _fileNameToBeStoredAs = GlobalConstants.DownloadLanguageConfigurationXmlFilename, string _zipFilePassword = GlobalConstants.DownloadZipsPassword)
        {

            urlToBeDownloaded = _urlToBeDownloaded; 
            fileNameToBeStoredAs = _fileNameToBeStoredAs;
            zipFilePassword = _zipFilePassword;

            System.Uri targetUri = new System.Uri(urlToBeDownloaded);
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUri);

            request.BeginGetResponse(new AsyncCallback(WebRequestCallBack), request);
        }


        void WebRequestCallBack(IAsyncResult result)
        {
            HttpWebRequest resultInfo = (HttpWebRequest)result.AsyncState;
            response = (HttpWebResponse)resultInfo.EndGetResponse(result);
            try
            {

                using (StreamReader httpwebStreamReader = new StreamReader(response.GetResponseStream()))
                {
                    //open isolated storage to save files
                    using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        using (ZipInputStream s = new ZipInputStream(httpwebStreamReader.BaseStream))
                        {
                            if (zipFilePassword != String.Empty)
                                s.Password = zipFilePassword;//if archive is encrypted

                            ZipEntry theEntry;
                            try
                            {
//EXCEPTION OCCURS ON THE VERY NEXT LINE (while...)    
                                while ((theEntry = s.GetNextEntry()) != null)
                                {
                                    string directoryName = Path.GetDirectoryName(theEntry.Name);
                                    string fileName = Path.GetFileName(theEntry.Name);
                                    fileName = fileNameToBeStoredAs;

                                    // create directory
                                    if (directoryName.Length > 0)
                                    {
                                        isoStore.CreateDirectory(directoryName);
                                        //Directory.CreateDirectory(directoryName);
                                    }

                                    if (fileName != String.Empty)
                                    {

                                        //save file to isolated storage
                                        using (BinaryWriter streamWriter =
                                                new BinaryWriter(new IsolatedStorageFileStream(theEntry.Name,
                                                FileMode.Create, FileAccess.Write, FileShare.Write, isoStore)))
                                        {

                                            int size = 2048;
                                            byte[] data = new byte[2048];
                                            while (true)
                                            {
                                                size = s.Read(data, 0, data.Length);
                                                if (size > 0)
                                                    streamWriter.Write(data, 0, size);
                                                else
                                                    break;
                                            }
                                        }
                                    }
                                }
                            }
                            catch (ZipException ze)
                            {
                                Debug.WriteLine(ze.Message);
                            }
                        }
                    }
                }
            } //try
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

        }//WebRequestCallBack Method */
    } //Class ends
}

输出栈

    Step into: Stepping over method without symbols 'string.operator !='
    Step into: Stepping over method without symbols 'ICSharpCode.SharpZipLib.Zip.ZipInputStream.Password.set'
    Step into: Stepping over method without symbols 'string.operator !='
    Step into: Stepping over method without symbols 'ICSharpCode.SharpZipLib.Zip.ZipInputStream.Password.set'
    Step into: Stepping over method without symbols 'ICSharpCode.SharpZipLib.Zip.ZipInputStream.GetNextEntry'
    A first chance exception of type 'ICSharpCode.SharpZipLib.Zip.ZipException' occurred in SharpZipLib.WindowsPhone7.dll
    Step into: Stepping over method without symbols 'System.Exception.Message.get'
    Step into: Stepping over method without symbols 'System.Diagnostics.Debug.WriteLine'
    Wrong Local header signature: 0x6D74683C
    A first chance exception of type 'ICSharpCode.SharpZipLib.Zip.ZipException' occurred in SharpZipLib.WindowsPhone7.dll
    Wrong Local header signature: 0x6D74683C

最佳答案

头码0x6D74683C对应ASCII序列<htm ,我认为这是网页中被截断的 HTML header 。如果您正在下载 .zip 存档的内容,那么这可能意味着 Web 服务器正在返回 HTML 代码而不是预期的存档(错误页面或类似内容)。也许您应该在将流提供给 ICSharpCode.SharpZipLib 之前检查 HTTP Content-Type header 。

关于c# - 有谁知道这个错误 : "Wrong Local header signature: 0x6D74683C"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16253543/

相关文章:

c# - 为什么ushort + ushort等于int?

c# - 保护应用程序和后台代理之间共享的等存储数据

c# - 如何在 c# asp.net 中制作下载按钮?与查询?

c# - 所有图像效果的颜色矩阵

c# - Mono 中的 XML 序列化问题

windows-phone-7 - CameraCaptureTask 在 WP7 中仅返回分辨率为 1296x972 的图片

r - 如何在R中下载谷歌工作表中的所有工作表

asp.net - 下载 Office 文件会导致 aspx 页面在打开文件之前重新加载 3 次

c# - Mapper 类中的参数超出范围异常

c# - XNA 中的 FPS 风格相机目标计算