Solved

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

Posted on 2011-02-18
1
391 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
array not updating 8 42
c#, case, if 4 38
C# LINQ 5 45
When adding onclick=location.href under button control the validation not working! Need someone to check the code. 1 31
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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