我正在尝试使用 google oauth2 对我的 Web 应用程序进行身份验证。我使用 vb.net 作为后面的代码。
现在从代码接收代码后,我在 test1.aspx 的页面加载上使用了代码
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsNullOrEmpty(Request.QueryString("code")) Then
Dim buffer As Byte() = Encoding.UTF8.GetBytes("code=" + Request.QueryString("code") + "&client_id=XXX.apps.googleusercontent.com&client_secret=XXX&redirect_uri=https%3A%2F%2Flocalhost:2690%2Ftest1.aspx&grant_type=authorization_code")
Dim req As HttpWebRequest = WebRequest.Create("https://accounts.google.com/o/oauth2/token")
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
req.ContentLength = buffer.Length
Dim strm As Stream = req.GetRequestStream()
strm.Write(buffer, 0, buffer.Length)
strm.Close()
Try
Dim res As HttpWebResponse = req.GetResponse()
Response.Write(res.StatusDescription)
Catch wex As WebException
Response.Write(wex.Data.ToString + "<br/>" + wex.InnerException.ToString + "<br/>" + wex.Message + "<br/>" + wex.TargetSite.ToString)
End Try
End If
End Sub
每次我从服务器收到错误的请求错误。请帮助我找出我做错了什么。我也尝试使用 dotnetopenauth,但每个示例都使用 mvc 和 c#,而我只知道 vb.net。谢谢你的帮助…。