Chilkat HTTP Default and Auto-Generated Headers

Chilkat HTTP automatically adds default headers, including Accept and Accept-Encoding, and manages headers like Host and Content-Length. For requests with a non-empty body, such as POST and PUT, Chilkat calculates and includes the Content-Length header. However, for bodyless requests like GET and DELETE, this header is omitted. Applications should not manually add the Content-Length header, as Chilkat ensures accurate computation upon sending the request. The Host header is added automatically, derived from the domain in the URL. While applications can modify or remove the Accept and Accept-Encoding headers if desired, it's usually unnecessary. For instance, a raw HTTP/1.1 request generated by Chilkat.Http.HttpJson would appear as follows:

POST /some/endpoint HTTP/1.1
Host: example.com
Accept: */*
Accept-Encoding: gzip
Content-Type: application/json
Content-Length: 26

{"name":"John","id":123}

Explanation in context:

  • POST /some/endpoint HTTP/1.1 — The client is making a POST request to /some/endpoint on the example.com server.
  • The next five lines are the HTTP request headers.
  • After the blank line, the JSON body begins — in this case {name:John,id:123} which is exactly 26 bytes in UTF-8.
  • The Content-Type header is typically specified in a method argument, or can be implied by a particular method.

Here’s what each HTTP header means:

Header Purpose Example Meaning in Your Case
Host: example.com Specifies the target domain name (and optionally port) of the server you want to reach. Required in HTTP/1.1 to handle virtual hosting. The request is directed to the "chilkatsoft.com" server.
Accept: */* Tells the server what content types the client can handle, using MIME types. "*/*" means “I can accept any content type.” The client is willing to accept any type of response body (HTML, JSON, XML, etc.).
Accept-Encoding: gzip Indicates which content encodings (compression methods) the client supports for the response. The client can handle gzip-compressed responses, allowing smaller downloads.
Content-Type: application/json Specifies the media type of the request body. The request body is JSON data.
Content-Length: 26 The size of the request body in bytes. Required for some HTTP methods (e.g., POST) so the server knows when the body ends. The JSON body is 26 bytes long.