login about faq

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?

asked May 15 '14 at 04:41

Gerben%20Abbink's gravatar image

Gerben Abbink
1111


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?)

link

answered May 19 '14 at 12:13

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

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"
link

answered May 15 '14 at 11:11

jpbro's gravatar image

jpbro ♦
1.1k2618

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.

link

answered May 15 '14 at 16:46

Gerben%20Abbink's gravatar image

Gerben Abbink
1111

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?

link

answered May 15 '14 at 20:29

jpbro's gravatar image

jpbro ♦
1.1k2618

I just tried with 9.5.0.39, and neither PUT nor POST now will show the Content-Length header when there is no content body. Maybe we need an option to do this?

(May 15 '14 at 20:44) jpbro ♦

Also tried calling AddStringForUpload "", "", "", "" to see if that would force the Content-Length header to appear. It did, but it had a value of 1 and the body wasn't empty (it was =)

(May 15 '14 at 20:46) jpbro ♦

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.

link

answered May 16 '14 at 02:13

Gerben%20Abbink's gravatar image

Gerben Abbink
1111

I suspect there is some logic that is removing the Content-Length header when generating the request text, even when explicitly set using AddHeader. This is something only Chilkat can answer though, so hopefully we will hear something soon.

Note the AddHeader documentation states: If a header having the same field name is already present, this method replaces it. - but this does not seem to be the case for the Content-Length header (which I suspect is being treated as a special case so that the library always sends the actual content length, except in case of 0 length bodies).

(May 16 '14 at 11:20) jpbro ♦
Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

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

Tags:

×186
×2

Asked: May 15 '14 at 04:41

Seen: 1,462 times

Last updated: May 19 '14 at 12:13

powered by OSQA