Why I get 411 Length required error?

前端 未结 8 1815
我寻月下人不归
我寻月下人不归 2020-12-04 19:01

This is how I call a service with .NET:

var requestedURL = \"https://accounts.google.com/o/oauth2/token?code=\" + code + \"&client_id=\" + client_id + \"         


        
相关标签:
8条回答
  • 2020-12-04 19:36

    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>
    
    0 讨论(0)
  • 2020-12-04 19:40

    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;

    0 讨论(0)
提交回复
热议问题