Why I get 411 Length required error?

前端 未结 8 1857
我寻月下人不归
我寻月下人不归 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:29

    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

提交回复
热议问题