google oauth access token 411 response

I'm working with google's OAuth api for web server applications, specifically asp.net mvc, and i'm able to get to the point where google returns an authorization code for a certain oauth request. At that point, I'm trying to obtain the access token using the following code:

public ActionResult GetOAuthToken()
{
     HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(OAuthConfig.getTokenUrl(Request.QueryString["code"].ToString()));
     myReq.Method = "POST";
     myReq.Host = "accounts.google.com";
     myReq.ContentType = "application/x-www-form-urlencoded";
     WebResponse resp = myReq.GetResponse();
     return View();
 }

The OAuthConfig is just a class I wrote that contains a method getTokenUrl(), which returns a url with parameters such as code, client_secret, client_id etc. for the url: https://accounts.google.com/o/oauth2/token. I've debugged and checked that there's nothing wrong with this url.

I keep getting the following error: The remote server returned an error: (411) Length Required.

I don't know what to specify for the content length, or if there's something else that i need to include to fix this error?


Have you tried to have a look at Google-API .NET Client?

If you debug you will see Google uses "length" as an internal property when sending access-token request. you can try to fix it on your own, but you can use THEIR class in order to send the token request; If you use their class you do not have to worry about internal such as length...

链接地址: http://www.djcxy.com/p/68436.html

上一篇: Salesforce OAuth 2.0用户

下一篇: 谷歌oauth访问令牌411响应