Archived Forum Post

Index of archived forum posts

Question:

Need Content-Length=0 HTTP header, even when message is empty.

May 19 '14 at 12:13

Hi,

I am using IChilkatHttp.SynchronousRequest() to create a file on a HTTP server, using 'PUT'. The file should be empty (zero bytes). This works on most servers, but now i am working on a server that responds (after a delay of a few seconds) with this error:

HTTP/1.1 411 Length Required
Content-Type: text/html
Date: Thu, 15 May 2014 08:36:38 GMT
Connection: close
Content-Length: 24

<h1>Length Required</h1>

This happens: if no bytes are being send, the Content-Length header parameter should be 0, but it is automatically ommitted by Chilkat.

It this is bug? How can i force the Content-Length=0 header parameter?


Answer

I made the change to ensure that the Content-Length header is always added to the HTTP request, even if 0. What build do you need? (Programming language, operating system, .NET Framework, 32/64-bit, etc?)


Answer

In case it is a bug in the library (not sure if it is supposed to always send the content length, even when it is 0 bytes), I would first recommend making sure you are using the latest version and try your existing code with it.

If it still fails, you can try calling the AddHeader method on your ChilkatHttpRequest object. For example:

request.AddHeader "Content-Length", "0"

Answer

I tried it, but it doesn't work. I use Fiddler to see what HTTP request is send to the server. Even if i call AddHeader "Content-Length", "0", the http parameter "Content-Length" is still not part of the HTTP header.


Answer

RFC2616 says that the Content-Length header should be sent (but not must). See: RFC2616 14.13

I can't see anyway to force the header to appear for PUT (although when using POST it does seem to appear in the header). That said, I've only tested with 9.4 so far - did you try with the latest 9.5 library as well?


Answer

It seems to me it's a bug in the Chilkat library. If there's a body in a PUT message, the Content-Length header is included in the message body (although it's optional), but if there's no body the Content-Length is omitted. There's no way i can change it to "Content-Length: 0".

I have no control over the implementation of the server am i trying to connect to (actually my clients are trying to connect to), i can only ask for a small change in the Chilkat library.