Google OAUTH2.0을 사용하여 웹 사이트를 방문한 사용자를 인증하고 싶습니다.방법 게시글의 WebRequest에 응답을 얻을 수 없습니다.
나는 성공적으로 응답으로 authorization_code를 얻었으며 지금은 액세스 토큰을받을 때 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'가 무엇을 설명 할 수 있습니까? 이 문자열 중 하나 또는 둘 모두를 POST하려고합니까? 콘텐츠 길이 계산을위한 – JoshVarty
개의 애드온 당신은 내가 webrequest.create 자체에서 모든 것을 언급했기 때문에 나는 포스트 데이터를 사용하지 않는다고 말했듯이 –
그것의 작업 ... 감사합니다. 'JoshVarty'에 대한 답변입니다. –