Archived Forum Post

Index of archived forum posts


PostMime problem

Dec 06 '12 at 03:56

I need to send raw post data (not structured as param1->value&param2->value and so on). So I use the following code:

Chilkat.Http http = new Chilkat.Http();
        http.UnlockComponent("My code");
        Chilkat.HttpRequest request = new Chilkat.HttpRequest();
        Chilkat.HttpResponse response = null;

        http.SessionLogFilename = "C:\\Users\\kolchakA\\Documents\\SessionLogFilename.txt";
        http.VerboseLogging = true;

        http.SaveCookies = true;
        http.SendCookies = true;

        string rawDataToPOST = "rawdata_so_simple";

        response = http.PostMime("", rawDataToPOST);


But I get null responce. Below I provide SessionLogFilename.txt


---- Sending ---- POST /clientsite/cookdir/ HTTP/1.1 rawdata_so_simple



You first need to become familiar with the most basic concepts of HTTP. All HTTP requests and responses are MIME messages. You just can't throw garbage at the server and expect a valid response. If you're sending a POST, then it must include a Content-Length header indicating the exact length of the MIME body. Calling SendMime assumes you are a little familiar with HTTP and MIME. If not, I would highly recommend the O'Reilly book "HTTP: The Definitive Guide".

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.


can I send raw POST data (not structured as param1->value&param2->value and so on) in some other way (without being little familiar with HTTP and MIME)?


can you provide me simple example of post mime usage?