![](/img/trans.png)
[英]Can an ASP.NET HttpHandler handle an http 400 - Bad Request?
[英](400) Bad Request error running asp.net site at local host
我設計了一個用於Facebook數據訪問的網站,而我在localhost:4999端口訪問它時,只要頁面加載,就會出現錯誤
public class FacebookLoginHelper
{
public Dictionary<string,> GetAccessToken(string code, string scope,string redirectUrl)
{
Dictionary<string,> tokens = new Dictionary<string,>();
string clientId = FacebookApplication.Current.AppId;
//FacebookContext.Current.AppId;
string clientSecret = FacebookApplication.Current.AppSecret;
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}&scope={4}",
clientId, redirectUrl, clientSecret, code, scope);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string retVal = reader.ReadToEnd();
foreach (string token in retVal.Split('&'))
{
tokens.Add(token.Substring(0, token.IndexOf("=")),
token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
}
}
return tokens;
}
}
現在它在行上顯示錯誤400:使用(HttpWebResponse response = request.GetResponse()as HttpWebResponse)
是什么原因 ? 請幫幫我嗎?
謝謝
當其中一個參數對於您要執行的請求無效時,Facebook API返回400錯誤的請求錯誤,您可以嘗試在瀏覽器中手動粘貼請求的URL和參數,它應該顯示JSON錯誤的原因(在Chrome或Firefox上),例如:
{
"error": {
"type": "OAuthException",
"message": "redirect_uri isn't an absolute URI. Check RFC 3986."
}
從那時起,您可以檢查出什么問題並修復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.