简体   繁体   English

SendToZip和C#CreateFromDirectory zipfile之间的区别

[英]Difference between SendToZip and C# CreateFromDirectory zipfile

I am using RestSharp to send a POST request, the POST request contains a zip file along with the following headers: 我正在使用RestSharp发送POST请求,该POST请求包含一个zip文件以及以下标头:

        request.AddParameter("username", this.username, ParameterType.GetOrPost);
        request.AddParameter("userid", this.userid, ParameterType.GetOrPost);
        request.AddParameter("projectid", this.projectid, ParameterType.GetOrPost);
        //add the file
        request.AddFile("os_serverpackage", this.filelocation);
        request.AlwaysMultipartFormData = true;

In C# I am sending the request synchronously. 在C#中,我正在同步发送请求。

The file is making it to the server, we can see it coming through, so we don't think it is a RestSharp issue. 该文件正在发送到服务器,我们可以看到它通过,所以我们认为这不是RestSharp的问题。

The problem we are having is the zip file is not being properly handled by our server (which is a node-backed server built on an ubuntu machine). 我们遇到的问题是我们的服务器(这是在ubuntu计算机上构建的节点支持的服务器)未正确处理zip文件。

So we think the problem is the way we're using C# libraries to create the zip file. 因此,我们认为问题在于我们使用C#库创建zip文件的方式。

The problem is when I send the same document as a zip file which was created with the sendToZip functionality on the desktop (windows) it works. 问题是,当我发送与使用sendToZip功能在桌面(Windows)上创建的zip文件相同的文档时,它可以工作。 However when I create the zip using C#'s native System.IO.Compression.ZipFile.CreateFromDirectory method to create the zip file, the server fails to respond. 但是,当我使用C#的本机System.IO.Compression.ZipFile.CreateFromDirectory方法创建zip文件来创建zip文件时,服务器无法响应。

What is the difference between the two? 两者有什么区别?

I am using C#'s native System.IO.Compression.ZipFile.CreateFromDirectory method to create the zip file. 我正在使用C#的本机System.IO.Compression.ZipFile.CreateFromDirectory方法创建zip文件。

We're not experts on zip and compression, or using .NET to compress files, but we've done some basic troubleshooting. 我们不是zip和压缩专家,也不是使用.NET压缩文件的专家,但是我们已经完成了一些基本的故障排除。 When we open one of these zip files on a Mac (a *nix machine of sorts), that originated from our .NET compression, we run into a problem where the zip is turned into a CPGZ and things look odd as outlined in this link http://osxdaily.com/2013/02/13/open-zip-cpgz-file/ . 当我们在Mac(某种* nix机器)上从.NET压缩中打开这些zip文件中的一个时,我们遇到了一个问题,其中zip变成了CPGZ,事情看起来很奇怪,如此链接所述http://osxdaily.com/2013/02/13/open-zip-cpgz-file/

Another option we have is to change the way our node server handles the zip files. 我们还有另一个选择是更改节点服务器处理zip文件的方式。 The server at the receiving end of the POST request is using adm-zip to extract the zip file. POST请求接收端的服务器正在使用adm-zip提取zip文件。

Do any compression experts have any tips on ways to leverage these libraries to ensure that our zip file works cross platform? 是否有任何压缩专家对如何利用这些库以确保我们的zip文件可跨平台工作提供任何技巧?

Seems to me that you're missing this (caveat: I'm not familiar with RestSharp): 在我看来,您缺少此功能(注意:我对RestSharp不熟悉):

request.AddHeader("Content-Type", "application/zip, application/octet-stream");

I know that Linux servers tend to be fussy about correct Content-Type HTTP headers and if you don't set it correctly then it won't be seen. 我知道Linux服务器往往对正确的Content-Type HTTP标头很挑剔,如果您没有正确设置它,就不会被看到。 At the very least you should use something like Fiddler2 to see if your messages are being transmitted correctly 至少您应该使用Fiddler2之类的东西来查看您的消息是否正确传输

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM