Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-02-18
1
Medium Priority
?
396 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

824 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