Why I get 411 Length required error?

http error 411. the request must be chunked or have a content length.
411 length required java
412 error
411 length required mr robot
java.lang.runtimeexception: failed : http error code : 411
error 411 exit
server returned http response code: 411
wcf 411 length required

This is how I call a service with .NET:

var requestedURL = "https://accounts.google.com/o/oauth2/token?code=" + code + "&client_id=" + client_id + "&client_secret=" + client_secret + "&redirect_uri=" + redirect_uri + "&grant_type=authorization_code";
HttpWebRequest authRequest = (HttpWebRequest)WebRequest.Create(requestedURL);
authRequest.ContentType = "application/x-www-form-urlencoded";
authRequest.Method = "POST";
WebResponse authResponseTwitter = authRequest.GetResponse();

but when this method is invoked, I get:

Exception Details: System.Net.WebException: The remote server returned an error: (411) Length Required.

what should I do?

When you're using HttpWebRequest and POST method, you have to set a content (or a body if you prefer) via the RequestStream. But, according to your code, using authRequest.Method = "GET" should be enough.

In case you're wondering about POST format, here's what you have to do :

ASCIIEncoding encoder = new ASCIIEncoding();
byte[] data = encoder.GetBytes(serializedObject); // a json object, or xml, whatever...

HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = data.Length;
request.Expect = "application/json";

request.GetRequestStream().Write(data, 0, data.Length);

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

Why I get 411 Length required error?, Hi all, I'm trying to get token by using POST with httpie command. http -a admin:​cisco POST  To explain further, here are the status codes. 4xx: Client Error. This error is sent back to the user when it is a client-side error. The user receives notifications of a bad request, content not found or unauthorized access to the content or something to that effect. 400 – Bad Request.

you need to add Content-Length: 0 in your request header.

a very descriptive example of how to test is given here

How to solve HTTP/1.1 411 Length Required error ? · Issue #713 , WebException: The remote server returned an error: (411) Length Required. This is a pretty common issue that comes up when trying to make  System.Net.WebException: The remote server returned an error: (411) Length Required. This is a pretty common issue that comes up when trying to make call a REST based API method through POST. Luckily, there is a simple fix for this one. This is the code I was using to call the Windows Azure Management API.

When you make a POST HttpWebRequest, you must specify the length of the data you are sending, something like:

string data = "something you need to send"
byte[] postBytes = Encoding.ASCII.GetBytes(data);
request.ContentLength = postBytes.Length;

if you are not sending any data, just set it to 0, that means you just have to add to your code this line:

request.ContentLength = 0;

Usually, if you are not sending any data, chosing the GET method instead is wiser, as you can see in the HTTP RFC

The remote server returned an error: (411) Length Required, 4×× Client Error. 411 Length Required. The server refuses to accept the request without a defined Content-Length. The client MAY repeat the request if it adds a  I'm so sorry for your time, after read your reply I did some tests, it did have the Content-Length header by default, by when I did this test on that server which has the 411 error, the Content-Length header is missing. Until now I found out it's a Nginx problem. I was careless that I didn't do the test on other server environment.

var requestedURL = "https://accounts.google.com/o/oauth2/token?code=" + code + "&client_id=" + client_id + "&client_secret=" + client_secret + "&redirect_uri=" + redirect_uri + "&grant_type=authorization_code";
HttpWebRequest authRequest = (HttpWebRequest)WebRequest.Create(requestedURL);
authRequest.ContentType = "application/x-www-form-urlencoded";
authRequest.Method = "POST";
//Set content length to 0
authRequest.ContentLength = 0;
WebResponse authResponseTwitter = authRequest.GetResponse();

The ContentLength property contains the value to send as the Content-length HTTP header with the request.

Any value other than -1 in the ContentLength property indicates that the request uploads data and that only methods that upload data are allowed to be set in the Method property.

After the ContentLength property is set to a value, that number of bytes must be written to the request stream that is returned by calling the GetRequestStream method or both the BeginGetRequestStream and the EndGetRequestStream methods.

for more details click here

411 Length Required, an external API you may receive HTTP 411 "Length Required" errors results in the HTTP 411 Length Required error response from certain  I'm not sure why the content-length property is being used when running in development, but not being used when I'm running in production. I'm using SMP server, and SMP SDK Thanks for your help,

Hey i'm using Volley and was getting Server error 411, I added to the getHeaders method the following line :


And it solved my issue

Receiving HTTP 411 "Length Required" response from external API , We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor  HTTP status 411 (Length Required) is usually raised when you are doing a POST but haven't specified the size of the body of the request (i.e. the length of the content that you are saving). Since you didn't post your code, I can't give you a more specific suggestion than: look at the properties of the class you are using to do the request.

Troubleshooting "HTTP/1.1 411 Length Required" error while using , UploadBinaryContent method we are getting the below error. "The remote server returned an error: (411) Length Required." Apprciate your help. Thanks,  The 411 Length Required response status code would indicate that the Content-Length header wasn't defined in your request. However, httpie (as well as curl) correctly sends Content-Length: 0 (zero-length content).

The remote server returned an error: (411) Length Required , It's useful for a client to not include a Content-Length header for a few different cases. In a situation like this, a recourse a client might have is to buffer the entire request to determine the real length. Example. HTTP/1.1 411 Length Required Content-Type: text/html Server: curveball/0.6.0 Client Error 4xx. Simon GoodmanSimon Goodman. 97311 gold badge66 silver badges2222 bronze badges. add a comment |. 2 Answers 2. ActiveOldestVotes. 1. The length is the length of the data you're writing to the request stream. So in this bit, set the ContentLength: using (var writer = new StreamWriter(webRequest.GetRequestStream())){ writer.Write(queryString); request.ContentLength = queryString.Length;}

411 Length Required, body, you will receive following error message: System.Net.WebException: '​The remote server returned an error: (411) Length Required.'. The HyperText Transfer Protocol (HTTP) 411 Length Required client error response code indicates that the server refuses to accept the request without a defined Content-Length header. Note: by specification, when sending data in a series of chunks, the Content-Length header is omitted and at the beginning of each chunk you need to add the length of the current chunk in hexadecimal format.

  • Can you please refer to my question "stackoverflow.com/questions/35308945/…" ? I am having similar issue. I am trying to hit the SFTP URL
  • Yes, adding Content-Length: 0 helped. Thanks!
  • simple and lifesaving. Thank you!
  • While customarily one would expect data to be sent with a POST, it would be incorrect and bad practice to use GET when you are modifying data on the server. A POST request should avoid any proxy caches between the client and server. GET is okay if data is being fetched from the server without the intention of anything changing on the server as a result of the request.