tags:

views:

33

answers:

1

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

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)

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?)

i am running apache/php on the webserver

thanks in advance

A: 

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.

Have you tried adding a header of type "Content-Encoding" and value "gzip" to your request?

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 :)

StephaneT