Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have a RestFUL API we build in PHP. If we make the request:

curl -u api-key:api-passphrase -X POST

We get back:

411 - Length Required

Though if we simply add -d "" onto the request it works and no 411 error. Is there a way to not require adding -d to the curl command?

We are using lighttpd web server, and believe its lighttpd NOT php who is returning the 411 error.

share|improve this question
up vote 11 down vote accepted

You are correct -- lighttpd doesn't support POST requests with an empty message body without a 'Content-Length' header set to zero, and CURL sends such a request. There's argument back and forth about who's right, but in my opinion, lighttpd is broken. A POST with no Content-Length and no Transfer-Encoding is perfectly legal and has no message body.

Adding -d "" causes CURL to send a Content-Length: 0 header, which resolves the problem.

You could modify lighttp. Find the code that issues the 411 error and instead set the content length to zero.

share|improve this answer
Thanks for the great explanation, so there is no flag to pass to curl besides -d "" or a config lighttpd directive to set? -d "" just looks like a hack. – Justin Sep 27 '11 at 8:37
It is a hack. If you want to fix the problem for real, you'd have to modify lighttpd. You can instead use -d @/dev/null if you think that looks better. You can also use -H "Content-Length: 0". (I tested both of these, they work.) – David Schwartz Sep 27 '11 at 8:50
Ok, thanks. -d "" seems to be the best option. – Justin Sep 27 '11 at 8:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.