我正在尝试使用google oauth2对我的网络应用程序进行身份验证 . 我使用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 + "
" + wex.InnerException.ToString + "
" + wex.Message + "
" + wex.TargetSite.ToString)
End Try
End If
End Sub
每次我从服务器收到错误的请求错误 . 请帮我弄清楚我做错了什么 . 我也尝试使用dotnetopenauth,但每个例子都使用mvc和c#,我只知道vb.net . 谢谢你的帮助… .
1 回答
此代码URL是否包含POST请求正文中的值 .
还要记住,代码要为令牌交换一次 .