Link to home
Start Free TrialLog in
Avatar of AndyH79
AndyH79Flag for United States of America

asked on

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

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();
            }
ASKER CERTIFIED SOLUTION
Avatar of Avodah
Avodah
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial