Why I get 411 Length required error?












37















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?










share|improve this question





























    37















    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?










    share|improve this question



























      37












      37








      37


      11






      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?










      share|improve this question
















      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?







      c# .net httprequest http-status-code-411






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 2 '14 at 19:54









      huseyint

      11.3k154575




      11.3k154575










      asked Aug 21 '13 at 8:15









      markzzzmarkzzz

      19k91233406




      19k91233406
























          8 Answers
          8






          active

          oldest

          votes


















          65














          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;





          share|improve this answer
























          • Can you please refer to my question "stackoverflow.com/questions/35308945/…" ? I am having similar issue. I am trying to hit the SFTP URL

            – Yash Saraiya
            Feb 10 '16 at 9:51



















          22














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



          a very descriptive example of how to test is given here






          share|improve this answer
























          • Yes, adding Content-Length: 0 helped. Thanks!

            – Roboblob
            Apr 22 '14 at 15:29











          • simple and lifesaving. Thank you!

            – Abraham Putra Prakasa
            Jul 19 '18 at 16:28



















          11














          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






          share|improve this answer


























          • thanks a lott ... it will useful for me

            – Swapnil Tandel
            Jun 24 '15 at 12:32






          • 1





            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.

            – Michael
            Apr 4 '16 at 4:57



















          3














          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






          share|improve this answer































            1














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



            params.put("Content-Length","0");


            And it solved my issue






            share|improve this answer































              0














              Google search



              2nd result




              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.
              This particular API call requires the request method to be set as
              POST, however there is no information that needs to be sent to the
              server.




              var request = (HttpWebRequest) HttpWebRequest.Create(requestUri);
              request.Headers.Add("x-ms-version", "2012-08-01"); request.Method =
              "POST"; request.ContentType = "application/xml";



              To fix this error, add an explicit content length to your request
              before making the API call.



              request.ContentLength = 0;







              share|improve this answer































                0














                I had the same error when I imported web requests from fiddler captured sessions to Visual Studio webtests. Some POST requests did not have a StringHttpBody tag. I added an empty one to them and the error was gone. Add this after the Headers tag:



                    <StringHttpBody ContentType="" InsertByteOrderMark="False">
                </StringHttpBody>





                share|improve this answer































                  -1














                  Change the way you requested the method from POST to GET ..






                  share|improve this answer

























                    Your Answer






                    StackExchange.ifUsing("editor", function () {
                    StackExchange.using("externalEditor", function () {
                    StackExchange.using("snippets", function () {
                    StackExchange.snippets.init();
                    });
                    });
                    }, "code-snippets");

                    StackExchange.ready(function() {
                    var channelOptions = {
                    tags: "".split(" "),
                    id: "1"
                    };
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                    StackExchange.using("externalEditor", function() {
                    // Have to fire editor after snippets, if snippets enabled
                    if (StackExchange.settings.snippets.snippetsEnabled) {
                    StackExchange.using("snippets", function() {
                    createEditor();
                    });
                    }
                    else {
                    createEditor();
                    }
                    });

                    function createEditor() {
                    StackExchange.prepareEditor({
                    heartbeatType: 'answer',
                    autoActivateHeartbeat: false,
                    convertImagesToLinks: true,
                    noModals: true,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: 10,
                    bindNavPrevention: true,
                    postfix: "",
                    imageUploader: {
                    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                    allowUrls: true
                    },
                    onDemand: true,
                    discardSelector: ".discard-answer"
                    ,immediatelyShowMarkdownHelp:true
                    });


                    }
                    });














                    draft saved

                    draft discarded


















                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18352190%2fwhy-i-get-411-length-required-error%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown

























                    8 Answers
                    8






                    active

                    oldest

                    votes








                    8 Answers
                    8






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    65














                    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;





                    share|improve this answer
























                    • Can you please refer to my question "stackoverflow.com/questions/35308945/…" ? I am having similar issue. I am trying to hit the SFTP URL

                      – Yash Saraiya
                      Feb 10 '16 at 9:51
















                    65














                    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;





                    share|improve this answer
























                    • Can you please refer to my question "stackoverflow.com/questions/35308945/…" ? I am having similar issue. I am trying to hit the SFTP URL

                      – Yash Saraiya
                      Feb 10 '16 at 9:51














                    65












                    65








                    65







                    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;





                    share|improve this answer













                    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;






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 21 '13 at 8:25









                    AtlasmaybeAtlasmaybe

                    1,094819




                    1,094819













                    • Can you please refer to my question "stackoverflow.com/questions/35308945/…" ? I am having similar issue. I am trying to hit the SFTP URL

                      – Yash Saraiya
                      Feb 10 '16 at 9:51



















                    • Can you please refer to my question "stackoverflow.com/questions/35308945/…" ? I am having similar issue. I am trying to hit the SFTP URL

                      – Yash Saraiya
                      Feb 10 '16 at 9:51

















                    Can you please refer to my question "stackoverflow.com/questions/35308945/…" ? I am having similar issue. I am trying to hit the SFTP URL

                    – Yash Saraiya
                    Feb 10 '16 at 9:51





                    Can you please refer to my question "stackoverflow.com/questions/35308945/…" ? I am having similar issue. I am trying to hit the SFTP URL

                    – Yash Saraiya
                    Feb 10 '16 at 9:51













                    22














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



                    a very descriptive example of how to test is given here






                    share|improve this answer
























                    • Yes, adding Content-Length: 0 helped. Thanks!

                      – Roboblob
                      Apr 22 '14 at 15:29











                    • simple and lifesaving. Thank you!

                      – Abraham Putra Prakasa
                      Jul 19 '18 at 16:28
















                    22














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



                    a very descriptive example of how to test is given here






                    share|improve this answer
























                    • Yes, adding Content-Length: 0 helped. Thanks!

                      – Roboblob
                      Apr 22 '14 at 15:29











                    • simple and lifesaving. Thank you!

                      – Abraham Putra Prakasa
                      Jul 19 '18 at 16:28














                    22












                    22








                    22







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



                    a very descriptive example of how to test is given here






                    share|improve this answer













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



                    a very descriptive example of how to test is given here







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 21 '13 at 8:26









                    EhsanEhsan

                    24.5k54157




                    24.5k54157













                    • Yes, adding Content-Length: 0 helped. Thanks!

                      – Roboblob
                      Apr 22 '14 at 15:29











                    • simple and lifesaving. Thank you!

                      – Abraham Putra Prakasa
                      Jul 19 '18 at 16:28



















                    • Yes, adding Content-Length: 0 helped. Thanks!

                      – Roboblob
                      Apr 22 '14 at 15:29











                    • simple and lifesaving. Thank you!

                      – Abraham Putra Prakasa
                      Jul 19 '18 at 16:28

















                    Yes, adding Content-Length: 0 helped. Thanks!

                    – Roboblob
                    Apr 22 '14 at 15:29





                    Yes, adding Content-Length: 0 helped. Thanks!

                    – Roboblob
                    Apr 22 '14 at 15:29













                    simple and lifesaving. Thank you!

                    – Abraham Putra Prakasa
                    Jul 19 '18 at 16:28





                    simple and lifesaving. Thank you!

                    – Abraham Putra Prakasa
                    Jul 19 '18 at 16:28











                    11














                    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






                    share|improve this answer


























                    • thanks a lott ... it will useful for me

                      – Swapnil Tandel
                      Jun 24 '15 at 12:32






                    • 1





                      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.

                      – Michael
                      Apr 4 '16 at 4:57
















                    11














                    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






                    share|improve this answer


























                    • thanks a lott ... it will useful for me

                      – Swapnil Tandel
                      Jun 24 '15 at 12:32






                    • 1





                      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.

                      – Michael
                      Apr 4 '16 at 4:57














                    11












                    11








                    11







                    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






                    share|improve this answer















                    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







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Aug 21 '13 at 8:30

























                    answered Aug 21 '13 at 8:25









                    SaveSave

                    6,72611322




                    6,72611322













                    • thanks a lott ... it will useful for me

                      – Swapnil Tandel
                      Jun 24 '15 at 12:32






                    • 1





                      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.

                      – Michael
                      Apr 4 '16 at 4:57



















                    • thanks a lott ... it will useful for me

                      – Swapnil Tandel
                      Jun 24 '15 at 12:32






                    • 1





                      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.

                      – Michael
                      Apr 4 '16 at 4:57

















                    thanks a lott ... it will useful for me

                    – Swapnil Tandel
                    Jun 24 '15 at 12:32





                    thanks a lott ... it will useful for me

                    – Swapnil Tandel
                    Jun 24 '15 at 12:32




                    1




                    1





                    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.

                    – Michael
                    Apr 4 '16 at 4:57





                    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.

                    – Michael
                    Apr 4 '16 at 4:57











                    3














                    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






                    share|improve this answer




























                      3














                      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






                      share|improve this answer


























                        3












                        3








                        3







                        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






                        share|improve this answer













                        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







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Aug 21 '15 at 9:49









                        Musakkhir SayyedMusakkhir Sayyed

                        4,07572956




                        4,07572956























                            1














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



                            params.put("Content-Length","0");


                            And it solved my issue






                            share|improve this answer




























                              1














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



                              params.put("Content-Length","0");


                              And it solved my issue






                              share|improve this answer


























                                1












                                1








                                1







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



                                params.put("Content-Length","0");


                                And it solved my issue






                                share|improve this answer













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



                                params.put("Content-Length","0");


                                And it solved my issue







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Mar 4 '15 at 8:05









                                shimi_tapshimi_tap

                                4,93441621




                                4,93441621























                                    0














                                    Google search



                                    2nd result




                                    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.
                                    This particular API call requires the request method to be set as
                                    POST, however there is no information that needs to be sent to the
                                    server.




                                    var request = (HttpWebRequest) HttpWebRequest.Create(requestUri);
                                    request.Headers.Add("x-ms-version", "2012-08-01"); request.Method =
                                    "POST"; request.ContentType = "application/xml";



                                    To fix this error, add an explicit content length to your request
                                    before making the API call.



                                    request.ContentLength = 0;







                                    share|improve this answer




























                                      0














                                      Google search



                                      2nd result




                                      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.
                                      This particular API call requires the request method to be set as
                                      POST, however there is no information that needs to be sent to the
                                      server.




                                      var request = (HttpWebRequest) HttpWebRequest.Create(requestUri);
                                      request.Headers.Add("x-ms-version", "2012-08-01"); request.Method =
                                      "POST"; request.ContentType = "application/xml";



                                      To fix this error, add an explicit content length to your request
                                      before making the API call.



                                      request.ContentLength = 0;







                                      share|improve this answer


























                                        0












                                        0








                                        0







                                        Google search



                                        2nd result




                                        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.
                                        This particular API call requires the request method to be set as
                                        POST, however there is no information that needs to be sent to the
                                        server.




                                        var request = (HttpWebRequest) HttpWebRequest.Create(requestUri);
                                        request.Headers.Add("x-ms-version", "2012-08-01"); request.Method =
                                        "POST"; request.ContentType = "application/xml";



                                        To fix this error, add an explicit content length to your request
                                        before making the API call.



                                        request.ContentLength = 0;







                                        share|improve this answer













                                        Google search



                                        2nd result




                                        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.
                                        This particular API call requires the request method to be set as
                                        POST, however there is no information that needs to be sent to the
                                        server.




                                        var request = (HttpWebRequest) HttpWebRequest.Create(requestUri);
                                        request.Headers.Add("x-ms-version", "2012-08-01"); request.Method =
                                        "POST"; request.ContentType = "application/xml";



                                        To fix this error, add an explicit content length to your request
                                        before making the API call.



                                        request.ContentLength = 0;








                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Aug 21 '13 at 8:28









                                        iabbottiabbott

                                        7651720




                                        7651720























                                            0














                                            I had the same error when I imported web requests from fiddler captured sessions to Visual Studio webtests. Some POST requests did not have a StringHttpBody tag. I added an empty one to them and the error was gone. Add this after the Headers tag:



                                                <StringHttpBody ContentType="" InsertByteOrderMark="False">
                                            </StringHttpBody>





                                            share|improve this answer




























                                              0














                                              I had the same error when I imported web requests from fiddler captured sessions to Visual Studio webtests. Some POST requests did not have a StringHttpBody tag. I added an empty one to them and the error was gone. Add this after the Headers tag:



                                                  <StringHttpBody ContentType="" InsertByteOrderMark="False">
                                              </StringHttpBody>





                                              share|improve this answer


























                                                0












                                                0








                                                0







                                                I had the same error when I imported web requests from fiddler captured sessions to Visual Studio webtests. Some POST requests did not have a StringHttpBody tag. I added an empty one to them and the error was gone. Add this after the Headers tag:



                                                    <StringHttpBody ContentType="" InsertByteOrderMark="False">
                                                </StringHttpBody>





                                                share|improve this answer













                                                I had the same error when I imported web requests from fiddler captured sessions to Visual Studio webtests. Some POST requests did not have a StringHttpBody tag. I added an empty one to them and the error was gone. Add this after the Headers tag:



                                                    <StringHttpBody ContentType="" InsertByteOrderMark="False">
                                                </StringHttpBody>






                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Apr 17 '18 at 12:48









                                                Youcef KelanemerYoucef Kelanemer

                                                479




                                                479























                                                    -1














                                                    Change the way you requested the method from POST to GET ..






                                                    share|improve this answer






























                                                      -1














                                                      Change the way you requested the method from POST to GET ..






                                                      share|improve this answer




























                                                        -1












                                                        -1








                                                        -1







                                                        Change the way you requested the method from POST to GET ..






                                                        share|improve this answer















                                                        Change the way you requested the method from POST to GET ..







                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited Nov 24 '18 at 16:11









                                                        Dipak Rathod

                                                        10712




                                                        10712










                                                        answered Nov 24 '18 at 10:30









                                                        Solomon ThomasSolomon Thomas

                                                        11




                                                        11






























                                                            draft saved

                                                            draft discarded




















































                                                            Thanks for contributing an answer to Stack Overflow!


                                                            • Please be sure to answer the question. Provide details and share your research!

                                                            But avoid



                                                            • Asking for help, clarification, or responding to other answers.

                                                            • Making statements based on opinion; back them up with references or personal experience.


                                                            To learn more, see our tips on writing great answers.




                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function () {
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18352190%2fwhy-i-get-411-length-required-error%23new-answer', 'question_page');
                                                            }
                                                            );

                                                            Post as a guest















                                                            Required, but never shown





















































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown

































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown







                                                            Popular posts from this blog

                                                            Create new schema in PostgreSQL using DBeaver

                                                            Deepest pit of an array with Javascript: test on Codility

                                                            Costa Masnaga