login about faq

There is a simple but very clear and easy example of using the POST command with the HTTP libary here:


It is exactly what I need. But I was wondering if there was an equally simple example in C# of how to implement the server side. I know that that is not a ChilKat job, but maybe someone has some code or a link lying around.....

asked Nov 08 '12 at 05:25

ofransen's gravatar image


HTTP requests and responses have the same format. They are composed of a "start line" followed by MIME. (For simplicity, I'm omitting the possibility of chunked responses.)

The "start line" of an HTTP request is a line such as:

GET /test/something.html HTTP/1.0
It has 3 parts: the HTTP method (GET, POST, PUT, etc.), the resource URI, and the HTTP protocol version. Following the start line is the MIME header, followed by the MIME body.

A server would consume an incoming HTTP request by reading the incoming data on the TCP socket (or possibly SSL/TLS connection) in the following way:
1) Consume the start line by reading until the first CRLF.
2) Consume the HTTP request header by reading until the first double CRLF.
3) If the HTTP request is GET, HEAD, or possibly some others, then the MIME body is assumed to be empty, and you are done. Perhaps the next HTTP request might be arriving on the same connection..
4) If a MIME body is to follow (and the MIME body might actually be a multi-part MIME message with nested multi-part MIME messages), then the total size of the entire MIME body is indicated in the "Content-Length" header field. The server should read this exact number of bytes to consume the full MIME body. The MIME body may include binary data, so it's best to read this into a byte array -- NOT a string.
5) Now that the server has both MIME header and body, compose the full MIME message in a byte array (the header followed by body) and then use the Chilkat MIME API to access the content of the MIME (you can get header fields, body content, navigate to MIME sub-parts, etc.)
6) The server's response would be a start line followed by MIME.

I think you probably get the general idea. I would highly recommend the O'Reilly book "HTTP: The Definitive Guide" as both a guide and reference if you're going to implement either the server-side or client-side of the HTTP protocol directly.

PS> If your server-side is custom-built to handle requests from a specific application, where the format of the requests are very controlled, and complexities can be avoided, then it's probably possible to roll-your-own HTTP server to handle the requests. However, writing a more general HTTP server is no small undertaking.


answered Nov 08 '12 at 10:38

chilkat's gravatar image

chilkat ♦♦

Thanks for the details which I'll surely need eventually. But I've already copied and implemented a very very simple C# example running on Azure which responds to a couple of REST verbs, I was wondering if there were other more complete examples.

I have limited neurons and learn mostly by example....!

(Nov 08 '12 at 11:00) ofransen

It has occurred to me that if the sources to testPostHandler.asp were in C# they would be ideal...

(Nov 09 '12 at 06:22) ofransen

This was the wrong place to ask I expect, but thanks for the detailed reply.


answered Nov 09 '12 at 06:18

ofransen's gravatar image



You're welcome. I'm sorry I don't have more time to provide examples. :)

(Nov 09 '12 at 08:53) chilkat ♦♦

No problems, I'm trying to knit together lots of new knowledge and it will take me time...

(Nov 09 '12 at 11:43) ofransen

Anyway, all you need to do is create a Azure Cloud solution containing an MVC4 project in VC2010 and much of the code is already there, with the default routing from arriving URI to C# function in a C# file called ValuesControllers.cs

Inside that there are some already defined sample functions, and one of them is:

    // POST api/values
    public void Post([FromBody]string value)

Upload the MVC program as a cloud package to Azure and you can test it from you MFC C++ Exe.


answered Nov 10 '12 at 09:22

ofransen's gravatar image


Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Nov 08 '12 at 05:25

Seen: 2,349 times

Last updated: Nov 10 '12 at 09:22

powered by OSQA