HTTP/1.1 411 Length Required on REST API Post call from Azure API Management Service

3k views Asked by At

curl -kvs -X POST https://xxxx-xxxx.azure-api.net/*******/reports -k  -H "account: ********"   -H "Ocp-Apim-Subscription-Key: ***********"

on making this curl, i'm getting the error message as HTTP/1.1 411 Length Required. I know we can fix this by adding the content -length header to the curl. But can we do something from azure apim level to get it fixed?

Thanks in Advance.

1

There are 1 answers

0
Mandar Dharmadhikari On

As per the HTTP 1.1 protocol the request made SHOULD have the Content-Length header supplied when a HTTP request is made to an endpoint. Following is the extract from the standard

The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.Applications SHOULD use this field to indicate the transfer-length of the message-body, unless this is prohibited by the rules in section 4.4.

   Content-Length    = "Content-Length" ":" 1*DIGIT

An example is

   Content-Length: 3495

This header is used as a part of the logic to determine the length of the message. This logic is explained in the section 4.4 of the RFC 2616. You can read about it at RFC 2616 Section 4.4 Message Length

If you have used an API testing tool like POSTMAN, you will see that it automatically adds the header to request that you send. Same is the case with Azure API Management developer portal, if you inspect the network traffic originating from the portal, you would see the content-length added to the request.

In a nutshell, you should not avoid sending the Content-Length header.