Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7179527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:09:30+00:00 2026-05-28T17:09:30+00:00

I wrote a simple httpserver which i plan to interact with with HttpRequest/Response. The

  • 0

I wrote a simple httpserver which i plan to interact with with HttpRequest/Response. The server gets the request and the parsing is fine but when i write back i get exception

System.Net.WebException: Der Server hat eine Protokollverletzung ausgeführt. Section=ResponseStatusLine
   bei System.Net.HttpWebRequest.GetResponse()

my servercode which writes back

TcpClient client = ...;
_stream = _client.GetStream();


// make sure "\r\n" is used as line ending, because it may be different on different OS
_output = new StreamWriter(_stream, Encoding.UTF8) { NewLine = "\r\n" };

length = 0;
code = 200;
message = "OK";
_output.WriteLine("HTTP/1.1 " + code + " " + message);
_output.WriteLine("Server: My Server");
_output.WriteLine("ContentLength: " + length);
_output.WriteLine("Connection: " + (_keepAlive ? "Keep-Alive" : "Close"));
_output.WriteLine();
_output.Flush();

client code

var request = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:8080/foo");
request.KeepAlive = false;
request.ServicePoint.Expect100Continue = false;

using (var res = request.GetResponse())   // throws here
{
}

any idea?

Update: as Jon mentioned first bug removed but still not working

alternate client code

using (var client = new TcpClient())
{
    client.Connect(new IPEndPoint(IPAddress.Loopback, 8080));
    using (var stream = client.GetStream())
    {
        var writer = new StreamWriter(stream);
        writer.WriteLine("GET /foo HTTP/1.1");
        writer.WriteLine("HOST:127.0.0.1");
        writer.WriteLine("Connection:Close");
        writer.WriteLine();
        writer.Flush();

        var response = new StreamReader(stream).ReadToEnd();
        foreach (var c in response)
        {
            if (char.IsControl(c))
                Console.Write("'{0}'" , (int)c);
            else
                Console.Write(c);
        }
    }
}

returns

HTTP/1.1 200 OK'13''10'Server: My custom Server'13''10'ContentLength: 0'13''10'Connection: Close'13''10''13''10'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:09:31+00:00Added an answer on May 28, 2026 at 5:09 pm

    Well this is very suspect to start with:

    _output = new StreamWriter(_stream, Encoding.UTF8) { NewLine = "\n\r" };
    

    I think you meant \r\n rather than \n\r.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a light http server in C which can handle simple requests. So
I wrote a simple server using socket API in C under linux which listens
I wrote a simple web service in C# using SharpDevelop (which I just got
I wrote a simple javascript image rotator which picks a random image on each
I wrote a simple CMS for one of my clients which does specifically what
For a university course I have to write a http server which is supposed
I wrote a simple HTTP client and server in Python for experimenting. The first
I try to implement simple server on python based on HTTPServer. How can i
I am writing a simple snippet which sends a simple post request. Currently I
I want to write a simple P2P test app which uses HTTP as underlying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.