有没有人知道这个错误:“错误的本地标头签名:0x6D74683C"
本文关键字:错误 0x6D74683C quot 没有人知道 | 更新日期: 2023-09-27 18:11:12
以下代码用于下载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
报头代码0x6D74683C对应于ASCII序列<htm
,我认为这是网页中截断的HTML报头。如果您正在下载.zip归档文件的内容,那么这可能意味着web服务器返回的是HTML代码,而不是预期的归档文件(错误页面或类似的东西)。也许你应该检查HTTP的内容类型头在提供流给ICSharpCode.SharpZipLib.
当您使用WP7时,您会收到来自dropbox的html:
找到资源被发现在{"你的新链接在这里};你应该是自动重定向。------------------------------------ WSGI服务器
在Wp8中此重定向自动工作,但在Wp7中此重定向不起作用。
我认为你的解决方案:只是改变链接到新的(你可以找到它在html文件,你收到)
这个问题和"Leandro Taset"answers"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);
}