【发布时间】:2012-11-17 05:35:21
【问题描述】:
我正在使用 google 的 OAuth api 用于 Web 服务器应用程序,特别是 asp.net mvc,并且我能够到达 google 返回某个 oauth 请求的授权代码的地步。此时,我正在尝试使用以下代码获取访问令牌:
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();
}
OAuthConfig 只是我写的一个类,它包含一个方法 getTokenUrl(),它返回一个带有参数的 url,如 url 的 code、client_secret、client_id 等:https://accounts.google.com/o/oauth2/token。我已经调试并检查了这个网址没有任何问题。
我不断收到以下错误:远程服务器返回错误:(411) 长度要求。
我不知道为内容长度指定什么,或者我是否需要包含其他内容来修复此错误?
【问题讨论】:
标签: c# asp.net-mvc google-api oauth-2.0 google-oauth