0

I am trying to send data via sslstream from my c# webserver to a Browser. For some reason "Transfer-Encoding: chunked" is not working. Do you see any mistakes in my code below:

string header = HTTPServer.VERSION + " " + status + "\r\nContent-Type: " + mine + "\r\nTransfer-Encoding: chunked\r\n";
sslstream.Write(ASCIIEncoding.ASCII.GetBytes(header));

int total = data.Length;
int sent = 0;
int buffer = 2048;
string hex;

while (total > 0)
{
    if (total < buffer)
        buffer = total;
    hex = buffer.ToString("X");
    sslstream.Write(ASCIIEncoding.ASCII.GetBytes(hex + "\r\n"));
    sslstream.Write(data, sent, buffer);
    sslstream.Write(ASCIIEncoding.ASCII.GetBytes("\r\n"));
    sent += buffer;
    total -= buffer;
}
buffer = 0;
hex = buffer.ToString("X");
sslstream.Write(ASCIIEncoding.ASCII.GetBytes(hex + "\r\n"));
sslstream.Write(ASCIIEncoding.ASCII.GetBytes("\r\n"));
sslstream.Flush();
sslstream.Close();

Thank you!

4
  • define "is not working"; what happens, and how does this differ from what you expected to happen? Commented Mar 29, 2018 at 13:52
  • Browsers error message is "ERR_INVALID_CHUNKED_ENCODING", when im not using "transfer-encoding:chunked" data transfer works fine. In order to transfer large amount of data I want to implement chunked transfer. Thank you! Commented Mar 29, 2018 at 13:56
  • does it work without the TLS? to be honest, you're probably going to need to look at the raw generated byte stream (perhaps via fiddler or similar) to figure this out Commented Mar 29, 2018 at 14:00
  • ok thank you, I will have a look. Commented Mar 29, 2018 at 14:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.