Solved

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

Posted on 2011-02-18
1
387 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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now