Solved

Need to set up a url stream with the content encoding property set

Posted on 2011-02-18
1
390 Views
Last Modified: 2013-12-17
I need to be able to use some type of stream that allows me to set the Content-Encoding = gzip.  The HttpWebRequest allows me to set a Transfer-Encoding which I think is when each buffer is compressed individually.  My implementation is where the whole file is compressed and the buffer is reading portions of the compressed file.  If someone could let me know the correct object I should be using I would appreciate it. Also how to set the user and password information since I don't see that as an obvious available option for the HttpWebRequest object.

static private void SendFileUsingWebRequest(ref CClient Client)
            {
                  string url = "https://xxx.xxxx.xxx/tools/services/rest/v1/importreadingdata?MessageFormat=MeasurementsLite.Meter";
                  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                  request.Method = "POST";
                  request.ContentType = "application/x-protobuf";

                  Stream input = File.Open(Client.compressedFilePath,FileMode.Open);
                  Stream output = request.GetRequestStream();
                                    byte[] buffer = new byte[8096];
                  int read = -1;
                  while (read != 0)
                  {
                              read = input.Read(buffer, 0, 8096);
                              if (read != 0)
                              {
                                    output.Write(buffer, 0, read);
                              }
                  }
                  input.Close();
                  output.Close();
                  WebResponse response = request.GetResponse();
                  Client.responseCode = response.ToString();
            }
0
Comment
Question by:AndyH79
1 Comment
 
LVL 18

Accepted Solution

by:
Richard Lee earned 500 total points
ID: 34941785
Try adding the following header.

request.Headers.Add("Content-encoding", "gzip");

or even use deflate - bonus

request1.Headers.Add("Content-encoding", "deflate");

DaTribe
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question