代币C#的Google Auth Exchange代码
本文关键字:Exchange 代码 Auth Google 代币 | 更新日期: 2023-09-27 18:13:31
伙计们当我发出这个http请求时,我得到了一个错误
远程服务器返回错误:(400(错误请求
try
{
var request = (HttpWebRequest)WebRequest.Create("https://accounts.google.com/o/oauth2/token");
string postData = string.Format("code={0}&client_id={1}&client_secret={2}&redirect_uri={3}&grant_type=authorization_code", authCode, clientid, secret, redirectURI);
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
MessageBox.Show(responseString);
}
catch (WebException ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
我尝试了很多东西,比如:其他链接请求,UrlEncode,将响应放入using((中,但仍然是这个糟糕的请求。重点是从响应中获取accces令牌
我的重定向URI为null,需要为"urn:ietf:wg:oauth:2.0:oob"。提示:不要变成2HP。Rest