2013-04-27 29 views
13

Poniższy kod służy do pobierania pliku zip i rozpakowania go na telefonie.Czy ktoś wie o tym błędzie: "Zły lokalny podpis nagłówka: 0x6D74683C"?

Ten sam kod używany do pracy na WP7, zacząłem testowane na urządzeniu WP8, a dzieje się coś dziwnego ... teraz działa na WP8 ale NIE na WP7 więcej.

Na WP7 to daje ERROR:

Wrong Local header signature: 0x6D74683C 

Może ktoś mi powiedzieć co się dzieje tutaj?

obserwacja (2 dni po zaksięgowaniu pytanie)

Mam kilka uwag .... Dzielenie się tutaj szczegółowo (Image format) lub (Excel format)

KODEKS

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 
} 

STAN WYJŚCIOWY

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 
+0

można pisać cały stos wyjątek, bo myślę błąd ma coś todo z plikiem zip. Czy Twój wyjątek zaczyna się od ICSharpCode.SharpZipLib.Zip.ZipException? – MUG4N

+0

dodał dane wyjściowe. – wafers

+0

Utworzony zip z WINRAR-64 i WINRAR-32-bitowy. To nie pomogło – wafers

Odpowiedz

14

Kod nagłówka 0x6D74683C odpowiada sekwencji ASCII <htm, która, jak przypuszczam, jest obciętym nagłówkiem HTML na stronie internetowej. Jeśli pobierasz zawartość archiwum .zip, być może oznacza to, że serwer WWW zwraca kod HTML zamiast zamierzonego archiwum (strona błędu lub coś podobnego). Może powinieneś sprawdzić nagłówek HTTP Content-Type przed przesłaniem strumienia do ICSharpCode.SharpZipLib.

4

Podczas korzystania z WP7 otrzymasz html z Dropbox:

Found

The resource was found at {"your new link here}; you should be redirected automatically. ------------------------------------ WSGI Server

W ithis WP8 przekierowanie działa automatycznie, ale w WP7 to przekierowanie nie działa.

myślę dla Ciebie rozwiązanie: wystarczy zmienić link do nowych (można go znaleźć w pliku HTML, który odbiera)

1

problem był taki sam jak „Leandro Taset” i „d.lavysh” wyjaśnione w ich odpowiedzi. Jednak nadal nie wiadomo, dlaczego WP7 pobiera nagłówki HTML dodatków?

W każdym razie zmodyfikowany kod, który jest teraz działa dla obu urządzeń WP7 i WP8. Ten kod może również pobierać pliki z usługi Web Hosting lub z Dropbox.

Kod napisałem powyżej jest prawie taka sama, tylko zmodyfikował Download metody, które po modyfikacji wygląda tak:

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); 
    }