如何使用Web客户端C#中的COM preSS上传数据 [英] how to compress uploaded data using WebClient C#
问题描述
我使用的Web客户端与C# 以下code正常工作
I am using WebClient with C# the following code works fine
wc = new WebClient();
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
NameValueCollection nvc = new NameValueCollection();
nvc.Add("webdata", JsonConvert.SerializeObject(webdata));
response = wc.UploadValues(@"http://localhost/api/results", "PUT", nvc);
该应用程序是最有可能被用于通过移动数据连接,从而最大限度地降低成本,我想,以确保数据的COM pressed,因为它是所有TXT。我已经使用JSON代替XML来减小尺寸(并可能改变格式开销进一步减少)
The application is most likely to be used over a mobile data connection, so to minimize costs, i would like to make sure the data is compressed, as it is all txt. I have used json instead of xml to reduce the size (and could possibly alter the format to reduce overhead further)
我是否需要COM preSS数据也将其添加到Web客户端手动前 或者是有一些方法我可以告诉WebClient的,我的网络服务器能够处理COM pression (还是COM pression在Web服务器上只适用于下载工作?)
Do i need to compress the data it manually prior to adding it to the WebClient or is there some way i can tell WebClient that my webserver can handle compression (or does compression on the webserver only work for downloads?)
我在网络服务器上运行的Apache / PHP
i am running apache/php on the webserver
在此先感谢
推荐答案
的Http COM pression通常仅用于响应。有可能的COM preSS请求,但不是所有的web服务器将接受这些请求和DECOM preSS的它们。
Http compression is normally only used for responses. It is possible to compress requests, but not all web servers will accept these requests and decompress them.
你有没有尝试添加类型内容编码和值GZIP的标题,你的要求?
Have you tried adding a header of type "Content-Encoding" and value "gzip" to your request?
您还是得COM preSS内容手动与GZipStream和写入COM pressed字节出请求流虽然。
You'll still have to compress the contents manually with a GZipStream and write the compressed bytes out to the request stream though.
不要忘记刷新你的作家流,或者不是所有的数据都将通过网络发送:)
don't forget to flush your writers to the streams, or not all data will be sent over the wire :)
这篇关于如何使用Web客户端C#中的COM preSS上传数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!