아래 코드를 C# 언어로 사용하여 액세스 토큰을 얻으려고하고 있지만 400 개의 잘못된 요청 예외가 발생합니다.C# 4.0의 상자 인증
코드 :
WebRequest httpWReq = WebRequest.Create("https://www.box.com/api/oauth2/token");
string postData = "grant_type=authorization_code";
postData += "&code=" + Code;
postData += "&client_id=MY_CLIENT_ID";
postData += "&client_secret=MY_CLIENT_SECRET";
postData += "&redirect_uri=https://www.google.com";
byte[] data = Encoding.UTF8.GetBytes(postData);
httpWReq.Method = "POST";
httpWReq.ContentType = "application/x-www-form-urlencoding";
httpWReq.ContentLength = data.Length;
using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = httpWReq.GetResponse();
var responseStream = response.GetResponseStream();
using (var reader = new StreamReader(responseStream))
{
var responseReader = reader.ReadToEnd();
MessageBox.Show(responseReader);
}
하지만 항상 다음과 같은 오류 받고 있어요 :
{"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"}
어떻게이 문제를 극복 할 수 있습니까?
도움이 될 것입니다. 미리 감사드립니다.
감사합니다, Harish 레디
안녕하세요 John은 제안한대로 URL 인코딩을 시도했지만 여전히 동일한 문제에 직면하고 있습니다. 그리고 [Box API v2 SDK for .NET] (https://github.com/jhoerr/box-csharp-sdk-v2)은 accessToken 및 RefreshToken을 가져온 후에 유용 할 수 있습니다. 이 두 가지가 없다면 우리는 그 어떤 것도 할 수 없습니다. 두 번째 이유는 –
이었기 때문에 리디렉션 URI를 Box App의 구성 페이지와 코드에서 로컬 응용 프로그램으로 변경했지만 여전히 동일한 문제에 직면하고 있습니다. –
Harish, .Net 용 SDK는 생성 및 OAuth 토큰을위한 완벽한 솔루션을 제공 할 수 있습니다. 데모를 보려면 [MVC 기반 OAuth 예제] (https://github.com/jhoerr/box-csharp-sdk-v2.sample.oauth)를 확인하십시오. –