0
我想验证谁使用谷歌的OAUTH2.0访问我的网站的用户。无法得到响应WebRequest的方法
我已经成功地获得了授权代码的响应,现在当我在获取访问令牌时向Google发送'POST请求'时,我面临着问题。问题是,请求正在继续,我没有得到任何回应。
我在下面写的代码有什么问题吗?
StringBuilder postData = new StringBuilder();
postData.Append("code=" + Request.QueryString["code"]);
postData.Append("&client_id=123029216828.apps.googleusercontent.com");
postData.Append("&client_secret=zd5dYB9MXO4C5vgBOYRC89K4");
postData.Append("&redirect_uri=http://localhost:4180/GAuth.aspx&grant_type=authorization_code");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://accounts.google.com/o/oauth2/token?code=" + Request.QueryString["code"] + "&client_id=124545459218.apps.googleusercontent.com&client_secret={zfsgdYB9MXO4C5vgBOYRC89K4}&redirect_uri=http://localhost:4180/GAuth.aspx&grant_type=authorization_code");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string addons = "/o/oauth2/token?code=" + Request.QueryString["code"] + "&client_id=123029216828.apps.googleusercontent.com&client_secret={zd5dYB9MXO4C5vgBOYRC89K4}&redirect_uri=http://localhost:4180/GAuth.aspx&grant_type=authorization_code";
request.ContentLength = addons.Length;
Stream str = request.GetResponse().GetResponseStream();
StreamReader r = new StreamReader(str);
string a = r.ReadToEnd();
str.Close();
r.Close();
你正在构建你的'postData'字符串,而不是做任何事情。你能解释一下'addons'和'postData'的用途吗?你想要发布一个或两个这些字符串?用于内容长度计算的 – JoshVarty 2013-02-23 06:53:55
插件。正如你所说我不使用发布数据,因为我提到了webrequest.create本身的所有内容 – 2013-02-23 07:14:35
其工作...感谢'JoshVarty'你的答案。 – 2013-02-23 07:27:59