16

次のコードは、zip ファイルをダウンロードして電話で解凍するために使用されます。

同じコードが WP7 で動作していました。WP8 デバイスでテストを開始しましたが、奇妙なことが起こっています...現在はWP8 で動作しますが、WP7 では動作しませ

WP7 ではERRORが表示されます:

Wrong Local header signature: 0x6D74683C

誰かがここで何が悪いのか教えてもらえますか?

考察 (質問を投稿してから 2 日後)

いくつかの観察結果があります.... ここで詳細を共有します (画像形式) または ( Excel 形式)

コード

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
4

3 に答える 3

19

ヘッダー コード 0x6D74683C は ASCII シーケンス<htmに対応します。これは、Web ページの切り捨てられた HTML ヘッダーであると推測されます。.zip アーカイブのコンテンツをダウンロードしている場合、Web サーバーが目的のアーカイブではなく HTML コードを返している可能性があります (エラー ページなど)。ストリームを ICSharpCode.SharpZipLib にフィードする前に、HTTP Content-Type ヘッダーを確認する必要があるかもしれません。

于 2013-05-06T16:11:54.533 に答える
4

WP7 を使用すると、ドロップボックスから html を受け取ります。

見つかった

リソースは {"your new link here} で見つかりました。自動的にリダイレクトされます。 ------------------------------- ----- WSGI サーバー

Wp8 ではこのリダイレクトは自動的に機能しますが、Wp7 ではこのリダイレクトは機能しません。

私はあなたのための解決策だと思います:リンクを新しいものに変更するだけです(受け取ったhtmlファイルで見つけることができます)

于 2013-05-07T11:27:32.330 に答える
1

問題は、「Leandro Taset」と「d.lavysh」が回答で説明したものと同じでした。しかし、なぜ WP7 に HTML ヘッダーが追加されたのかはまだ不明です。

とにかく、修正されたコードは、WP7 と WP8 の両方のデバイスで動作するようになりました。このコードは、Web ホスティング サービスまたは DropBox からファイルをダウンロードすることもできます。

上記のコードはほとんど同じです。Downloadメソッドを変更しただけで、変更後は次のようになります。

    public async void Download(string _urlToBeDownloaded = GlobalConstants.DownloadLanguageConfigurationUrl, string _fileNameToBeStoredAs = GlobalConstants.DownloadLanguageConfigurationXmlFilename, string _zipFilePassword = GlobalConstants.DownloadZipsPassword)
    {
        //The following IF block is addition to the code above. 
        //Here the headers are checked and if "WP7" and the URL is pointing to  the "Dropbox", the inner URL is fetched out of the headers.
        if (GlobalVariables.IsWP7 && _urlToBeDownloaded.ToLower().Contains("dropbox"))
        {

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_urlToBeDownloaded);
            HttpWebResponse webResponse = await webRequest.GetResponseAsync() as HttpWebResponse;

            for (int i = 0; i < webResponse.Headers.Count; ++i)
            {
                if (webResponse.Headers.AllKeys[i].ToLower() == "location")
                {
                    _urlToBeDownloaded = webResponse.Headers["location"] ;
                    break;
                }
            }
        }

        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);
    }
于 2013-05-14T17:07:14.180 に答える