나는 https://developer.yahoo.com/oauth2/guide/에서 야후의 가이드에 따라 Yahoo OAuth 2.0을 구현 중이다. 내 코드는 "액세스 토큰에 대한 Exchange 인증 코드"라는 가이드의 4 단계에서 실패합니다. "원격 서버가 오류를 반환했습니다 : (400) Bad Request."오류가 발생했습니다. 내 앱이 실시간으로 오류를 볼 수있는 http://www.schoonheidsinstituut-antwerpen.com/yahooapi.aspx에 있습니다.원격 서버에서 오류를 반환했습니다 : (400) 잘못된 요청입니다. in yahoo Oath 2.0
내 C# 코드는 아래에 주어진다 -
string consumerKey = "mykey1";
string consumerSecret = "mykey2";
string returnUrl = "http://www.schoonheidsinstituut-antwerpen.com/yahooapi.aspx";
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["code"] != null)
GetAccessToken();
}
protected void yahooButton_Click(object sender, EventArgs e)
{
/*Sending User To Authorize Access Page*/
string url = "https://api.login.yahoo.com/oauth2/request_auth?client_id=" + consumerKey + "&redirect_uri=" + returnUrl + "&response_type=code&language=en-us";
Response.Redirect(url);
/*End*/
}
public void GetAccessToken()
{
/*Exchange authorization code for Access Token by sending Post Request*/
Uri address = new Uri("https://api.login.yahoo.com/oauth2/get_token");
// Create the web request
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
// Set type to POST
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Headers["Authorization"] = "Basic";
// Create the data we want to send
StringBuilder data = new StringBuilder();
data.Append("client_id=" + consumerKey);
data.Append("&client_secret=" + consumerSecret);
data.Append("&redirect_uri=" + returnUrl);
data.Append("&code=" + Request.QueryString["code"]);
data.Append("&grant_type=authorization_code");
// Create a byte array of the data we want to send
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
// Set the content length in the request headers
request.ContentLength = byteData.Length;
// Write data
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
// Get response
string responseFromServer = "";
try
{
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
responseFromServer = reader.ReadToEnd();
}
}
catch (Exception ex)
{
dataDiv.InnerHtml = ex.Message;
}
/*End*/
}
페이지 HTML 것은 -
<form id="form1" runat="server">
<div>
<asp:Button ID="yahooButton" Text="Get Yahoo Contact" runat="server" OnClick="yahooButton_Click" />
</div>
<div id="dataDiv" runat="server"></div>
</form>
은 내가 HTTP POST 요청이 400 오류 코드와 함께 실패는 사실을 알게 될 것입니다. 누군가이 오류의 원인을 찾는데 도와 주실 수 있습니까? 덕분에 .